<?php
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Img;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use phpDocumentor\Reflection\Types\Context;
class ImgController extends Controller
{
use HasResourceActions;
public function index( Content $content )
{
return $content->header( 'Index' )->description( 'description' )->body( $this->grid() );
}
public function show( $id , Content $content )
{
return $content->header( 'Detail' )->description( 'description' )->body( $this->detail( $id ) );
}
public function edit( $id , Content $content )
{
return $content->header( 'Edit' )->description( 'description' )->body( $this->form()->edit( $id ) );
}
public function create( Content $content )
{
return $content->header( 'Create' )->description( 'description' )->body( $this->form() );
}
protected function grid()
{
$grid = new Grid( new Img);
$grid->id( 'ID' )->sortable();
$grid->title();
$grid->imgs();
$grid->category_id ();
$grid->img()->display(function($img) {
return '<img src="'.$img.'" width=90px height=90px>';
}); $grid->created_at ( 'Created at' )->sortable ();
return $grid;
}
protected function detail( $id )
{
$show = new Show( Img::findOrFail( $id ) );
$show->id( 'ID' );
$show->img();
$show->source_url();
$show->created_at( 'Created at' );
$show->updated_at( 'Updated at' );
return $show;
}
protected function form()
{
$form = new Form( new Img );
$form->display( 'id' , 'ID' );
$form->file ( 'img' , 'img' );
$form->display( 'imgs' , 'imgs' ); $form->display( 'created_at' , 'Created At' );
$form->display( 'updated_at' , 'Updated At' );
return $form;
}
}