I am still new to laravel, and i need an option like "Orderable Grid" in this demo page admin/demo/articles. I did everything it did in code, schema and model tab.
so i put this code as ArticleController.php in app/Admin/Controllers/
namespace App\Admin\Controllers\Demo;
use App\Http\Controllers\Controller;
use App\Models\Article;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Widgets\Tab;
class ArticleController extends Controller
{
use ModelForm;
...
protected function grid()
{
return Admin::grid(Article::class, function (Grid $grid) {
$grid->model()->ordered();
$grid->id('ID')->sortable();
$grid->title()->editable();
$grid->content()->editable();
$grid->picture()->image();
$grid->order()->orderable();
$grid->created_at();
$grid->updated_at();
});
}
protected function form()
{
return Admin::form(Article::class, function (Form $form) {
$form->display('id', 'ID');
$form->text('title')->rules('required');
$form->textarea('content')->rules('required');
$form->image('picture');
$form->display('created_at', 'Created At');
$form->display('updated_at', 'Updated At');
});
}
...
}
Article.php in app/Models/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
class Article extends Model implements Sortable
{
use SortableTrait;
protected $table = 'demo_articles';
public $sortable = [
'order_column_name' => 'order',
'sort_when_creating' => true,
];
}
Any exceptions?
exceptions means? what should i do?
You need to define a route to point to this controller.
I suggest you go first to learn about laravel's routing definitions
So, i just a new line of codes in routes.php
And a new error appear
seems your controller in App\Admin\Controllers\Demo;
Try to change ArticleController@index to Demo\ArticleController@index
BTW:
You'd better use the follow route format:
$router->resource('articles', Demo\ArticleController::class);
I have done what you suggested, now got another error
Please confirm whether has method index in class ArticleController and try to use this route:
$router->resource('articles', Demo\ArticleController::class);
refer this:
http://z-song.github.io/laravel-admin/#/en/quick-start.md
i think theres none, only grid() and form(), how do i do that?
You can add the following code in ArticleController to do test:
public function index()
{
return Admin::content(function (Content $content) {
$content->header('header');
$content->description('description');
$content->body($this->grid());
});
}
If you want to use the full features. you'd better to generate your controller by artisan.
I suggest you to write one test case base on document step by step.
refer: http://z-song.github.io/laravel-admin/#/en/quick-start.md
Added the codes, now another error
Try:
composer require spatie/eloquent-sortable
Oh my, it works, thank you so much for the help.
Btw, how do i +rep you? Or theres no option for that haha
Most helpful comment
Try: