domihagen
02/23/2022, 5:05 PMdomihagen
02/23/2022, 5:05 PMamargoCactus
02/23/2022, 7:09 PMamargoCactus
02/23/2022, 7:09 PMamargoCactus
02/23/2022, 7:11 PMifox
02/23/2022, 9:53 PMifox
02/23/2022, 9:55 PMifox
02/23/2022, 9:56 PMamargoCactus
02/23/2022, 9:57 PMamargoCactus
02/23/2022, 9:57 PMamargoCactus
02/23/2022, 9:57 PMamargoCactus
02/23/2022, 9:58 PMifox
02/23/2022, 9:58 PM$block->image('name of the field', 'name of the crop')amargoCactus
02/23/2022, 9:58 PMuser
02/23/2022, 10:20 PMphp
// /Models/Page.php
namespace App\Models;
use A17\Twill\Models\Behaviors\HasBlocks;
use A17\Twill\Models\Behaviors\HasTranslation;
use A17\Twill\Models\Behaviors\HasSlug;
use A17\Twill\Models\Behaviors\HasRevisions;
use A17\Twill\Models\Behaviors\HasPosition;
use A17\Twill\Models\Behaviors\Sortable;
use A17\Twill\Models\Model;
class Page extends Model implements Sortable
{
use HasBlocks, HasTranslation, HasSlug, HasRevisions, HasPosition;
protected $fillable = [
'published',
'title',
'meta_title',
'meta_description',
'position',
];
public $translatedAttributes = [
'title',
'meta_title',
'meta_description',
'active',
];
public $slugAttributes = [
'title',
];
}
// PagesRepository.php
public function allPages()
{
return $this->model
->get();
}
// Controllers/PagesController.php
public function index()
{
return Inertia::render('Moe', [
'pages' => $this->repository->allPages()
]);
}
I'm also not sure where to look first? Laravel docs? Twill docs? Thanksuser
02/23/2022, 10:21 PMjson
[{"id":1,"position":1,"deleted_at":null,"created_at":"2022-02-19T00:11:29.000000Z","updated_at":"2022-02-23T21:48:45.000000Z","published":1,"title":"First Page","meta_title":null,"meta_description":null,"active":1,"translations":[{"id":2,"page_id":1,"title":"Erste Seite","meta_title":null,"meta_description":null,"deleted_at":null,"created_at":"2022-02-19T00:11:29.000000Z","updated_at":"2022-02-23T21:48:45.000000Z","locale":"de","active":0},{"id":1,"page_id":1,"title":"First Page","meta_title":null,"meta_description":null,"deleted_at":null,"created_at":"2022-02-19T00:11:29.000000Z","updated_at":"2022-02-23T21:48:45.000000Z","locale":"en","active":1}]}]pboivin
02/23/2022, 10:41 PMroutes/web.php. I could be wrong but I think even with Inertia.js you would use the route() helper to generate URLs.pboivin
02/23/2022, 10:42 PMuser
02/23/2022, 10:44 PMphp
Route::get('/pages', [PagesController::class, 'index'])->name('pages');pboivin
02/23/2022, 10:45 PMshow route that would display a single page? I imagine index will display a list of all pages?user
02/23/2022, 10:46 PMuser
02/23/2022, 10:47 PMpboivin
02/23/2022, 10:47 PMuser
02/23/2022, 10:48 PMRoute::get('/pages/{slug}', [PagesController::class, 'show'])->name('slug');
php
// Controller
public function show($slug)
{
$page = $this->repository->forSlug($slug);
abort_unless($page, 404, 'Page ');
return Inertia::render('Page', [
'data' => $page
]);
}user
02/23/2022, 10:48 PMpboivin
02/23/2022, 10:49 PMuser
02/23/2022, 10:50 PMurl afterwards
php
// Models/Page
protected $fillable = [
'published',
'title',
'url',
'meta_title',
'meta_description',
'position',
];pboivin
02/23/2022, 10:51 PM$url = route('slug', ['slug' => $page->slug])pboivin
02/23/2022, 10:51 PMurl field, unless you're doing something customuser
02/23/2022, 10:51 PM