Fork me on GitHub

DataEdit

You can extend Rapyd "AbstractDataEdit" to make custom {Entity}Edit to edit and create Entities.


Article Edit

Rerum unde officia sequi maiores beatae facere reiciendis. Quis est enim error asperiores laudantium. Qui molestias quia tenetur adipisci et sed. Blanditiis maxime velit qui ex aut quisquam.

route



    Route
::get('/article/edit/{article:id?}'ArticlesEdit::class)
        ->
name('articles.edit')
        ->
crumbs(function ($trail$article null) {
            if (
$article) {
                
$trail->parent('articles.view'$article)->push('Edit Article'route('articles.edit'$article));
            } else {
                
$trail->parent('articles')->push('Create Article'route('articles.edit'));
            }
        });

component

Http/Livewire/ArticlesEdit.php


<?php

namespace App\Http\Livewire;


use 
App\Models\Article;
use 
App\Models\Author;
use 
Zofe\Rapyd\Http\Livewire\AbstractDataEdit;


class 
ArticlesEdit extends AbstractDataEdit
{
    public 
$article;

    protected 
$rules = [
        
'article.title'   => 'required',
        
'article.author_id'=> 'required',
        
'article.body'    => 'nullable',
        
'article.public'  => 'nullable|boolean',
    ];

    public function 
mount(?Article $article)
    {
        
$this->article $article;
    }

    public function 
save()
    {
        
$this->validate();
        
$this->article->save();
        return 
redirect()->to(route('articles.view'$this->article->getKey()));
    }

    public function 
render()
    {
        
$authors Author::all()->pluck('firstname''id')->toArray();

        return 
view('livewire.articles.edit'compact('authors'));
    }
}

view

../resources/views/livewire/articles/edit.blade.php



    
<x-rpd::edit title="Article Edit">

        <
div class="row">
            <
div class="form-group col-md-4">
                <
x-rpd::input model="article.title" label="Title" />
            </
div>

            <
div class="form-group col-md-4">
                <
x-rpd::select model="article.author_id" :options="$authorslabel="Author" addempty />
            </
div>

            <
div class="form-group col-md-4 pt-2">
                <
x-rpd::checkbox model="article.public" label="Public" checkLabel="true" />
            </
div>
        </
div>
        <
div class="row mb-2">
            <
div class="form-group col-md-8">
                <
x-rpd::rich-text model="article.body" label="Body" />
            </
div>
        </
div>

        <
x-slot name="actions">
            <
button type="submit" class="btn btn-primary">Save</button>
        </
x-slot>

    </
x-rpd::edit>