Laravel-admin: [HELP] New page doesn't show, why?

Created on 8 Mar 2017  路  13Comments  路  Source: z-song/laravel-admin

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,
];

}

Most helpful comment

Try:

composer require spatie/eloquent-sortable

All 13 comments

Any exceptions?

exceptions means? what should i do?

capture

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
capture

And a new error appear
capture1

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
capture

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?

capture

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

capture

capture

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abufalbo picture abufalbo  路  3Comments

antranapp picture antranapp  路  3Comments

greentornado picture greentornado  路  3Comments

cdhraesaemer picture cdhraesaemer  路  3Comments

chenyongmin picture chenyongmin  路  3Comments