laravel-shift / blueprint

A code generation tool for Laravel developers.
MIT License
2.89k stars 275 forks source link

Extending controller statements to support Inertia render #707

Open hubbituk opened 4 days ago

hubbituk commented 4 days ago

Synopsis:

Popular stacks like Laravel + Inertia have a differerent way of rendering pages. Currently the only supported statement is render which creates a blade view file.

I would suggest creating a statement that can generate the code that supports inertia rendering syntax. For example render_inertia.

I tried to implement this by creating a blueprint extension however quickly realised that the statements are within the ControllerGenerator. To solve this I had to basically copy over the entire controller generator and add the inertiaJS statement at the end of the else if statements on line 184 in src/Generators/ControllerGenerator.php.

Right now my own version of the ControllerGenerator works for me however I am willing to extend the controller generator to support the inertia render command for everybodies use.

Proposed Syntax:

controllers:
  CustomerController:
    resource: show
    show:
      render_inertia: customer.show with:Customer

Expected Behavior:

public function show(Request $request, Customer $customer): 
{
    return Inertia::render('Customer/Index', ['customer' => $customer]);
}

What does the community think? Thank you

Tags:

jasonmccreary commented 3 days ago

I'm all for this as I'm currently working on adding Livewire support. So I'd be open to a inertia statement. Feel free to draft up a PR. Otherwise, I'll try to get to this in the coming weeks.