PHP code example of jcsoriano / laravel-crud-templates

1. Go to this page and download the library: Download jcsoriano/laravel-crud-templates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jcsoriano / laravel-crud-templates example snippets


public function rules(): array
{
    return [
        'title' => ['' => ['      'status' => ['

public function category(): BelongsTo
{
    return $this->belongsTo(Category::class);
}

public function comments(): HasMany
{
    return $this->hasMany(Comment::class);
}

protected $casts = [
    'published_at' => 'immutable_datetime',  // Automatic datetime casting
    'status' => PublishStatus::class,        // Enum casting
];

protected $fillable = [
    'title',
    'content',
    'published_at',
    'category_id',
    'status',
];

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->dateTime('published_at');
    $table->foreignId('category_id')->constrained();
    $table->string('status');
    $table->timestamps();
});

public function toArray($request): array
{
    return [
        ...
        'category' => CategoryResource::make($this->whenLoaded('category')),
        'comments' => CommentResource::collection($this->whenLoaded('comments')),
    ];
}
bash
php artisan vendor:publish --tag="crud-templates-stubs"