nasrulhazim
12/5/2016 - 1:54 PM

Reusable Basic Actions Component

Reusable Basic Actions Component

<div class="container">
	<a href="{{ route($route.'.create') }}" class="btn btn-success pull-right">New Record</a>
	{{ $resources->links() }}
	<table class="table table-condensed table-hover">
		<thead>
			<tr>
				@foreach($headings as $heading)
					<th>{{ $heading['label'] }}</th>
				@endforeach
				<th>Actions</th>
			</tr>
		</thead>
		<tbody>
			@foreach($resources as $resource)
				<tr>
					@foreach($headings as $heading)
						<td>{{ $resource->{$heading['attr']} }}</td>
					@endforeach
					<td>
						@include('components.actions', ['route' => $route, 'resource' => $resource])
					</td>
				</tr>
			@endforeach
		</tbody>
	</table>
	{{ $resources->links() }}
</div>
@extends('layouts.app')

@section('content')
	@include('components.list', [
		'route' => 'users',
		'resources' => $users,
		'headings' => [
			[
				'label' => 'Name',
				'attr' => 'name',
			],
			[
				'label' => 'E-mail',
				'attr' => 'email',
			],
		]
	])
@endsection
<div class="btn-group">
	<a href="{{ route($route.'.show', ['id' => $resource->id]) }}" class="btn btn-default">Details</a>
	<a href="{{ route($route.'.edit', ['id' => $resource->id]) }}" class="btn btn-primary">Edit</a>

    <a href="{{ route($route.'.destroy', ['id' => $resource->id]) }}"
    	class="btn btn-danger"
    	onclick="event.preventDefault();
    			if(confirm('{!! $confirm or 'Are you sure want to delete this record?' !!}')){document.getElementById('action-resource-form-{{ $resource->id }}').submit();}">
    	Delete
    </a>

    <form id="action-resource-form-{{ $resource->id }}"
    	action="{{ route($route.'.destroy', ['id' => $resource->id]) }}"
    	method="POST" style="display: none;">
        {{ csrf_field() }}
        {{ method_field('DELETE') }}
    </form>
</div>