我正在使用laravel 8,现在我想安装Vue.js。我正在尝试这样
composer require laravel/uiphp artisan ui vuephp artisan ui vue --auth这是我目前用来创建控制器和模型的
php artisan make:controller API/name_of_controller --api --model=name_of_model
Run Code Online (Sandbox Code Playgroud)
然后创建迁移
php artisan make:migration create_users_table
Run Code Online (Sandbox Code Playgroud)
过去在我开始使用 API 之前,我曾经这样做过在一行中创建模型、迁移和控制器
php artisan make:model Banana -mcr
Run Code Online (Sandbox Code Playgroud)
有没有办法用 API 控制器做到这一点?
当我获得所有记录时,它会起作用:
...
$items = Item::all();
return Inertia::render('Rentals/Items', ['items' => $items]
);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试分页时,它崩溃了:
...
$items = Item::paginate(15);
return Inertia::render('Rentals/Items', ['items' => $items]
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Uncaught (in promise) TypeError: Cannot read property 'id' of null
请帮忙。我究竟做错了什么?我已经被困了好几天了。
在以前的 Laravel 版本中,我在 tinker 中使用它:
php artisan tinker
factory(App\Banana::class, 3)->create();
Run Code Online (Sandbox Code Playgroud)
但是在 Laravel 8 中,它给出了这个错误:`PHP Error: Class 'Database/Factories/bananaFactory' not found
请如何使用 tinker 在 Laravel 8 中创建虚拟数据?谢谢你。