PHP code example of intrfce / laravel-inertia-components

1. Go to this page and download the library: Download intrfce/laravel-inertia-components 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/ */

    

intrfce / laravel-inertia-components example snippets


public function show(Request $request, string $id, ModelName $model): array {}

#[PatchAction(url:'/{post}/toggle-published')]
function togglePublished(BlogPost $post) {
    $post->published = !$post->published;
    $post->save();
    return redirect()->back();
}



class Dashboard extends Intrfce\InertiaComponents\InertiaComponent {

   // A template is 
    public string $name = 'Dan';
    
    // As are any public methods.
    public function email(): string 
    {
      return '[email protected]';
    }
    
    // You can mark any method as Inertia::lazy() with the #[Lazy] Attribute:
    #[Lazy]
    public function blogPosts(): Collection
    {
        return BlogPosts::all();
    }
    
    // You can mark any method as Inertia::always() with the #[Always] Attribute:
    #[Always]
    public function age(): int
    {
        return 36;
    }
    
    /** GET /dashboard */
    public function show(Request $request) {}
    
    /** POST /dashboard */
    public function store(Request $request) {}
    
    /** PUT/PATCH /dashboard */
    public function update(Request $request) {}
    
    /** DELETE /dashboard */
    public function destroy(Request $request) {}
    
    /** GET /dashboard/your-route - Autowired */
    #[GetAction('your-route')]
    public function getMoreStuff()
    {
    
    }
    
    /** POST /dashboard/your-route - Autowired */
    #[GetAction('your-route')]
    public function postMoreStuff()
    {
    
    }
    
    /** PATCH /dashboard/patch-more-stuff - Autowired  - notice the route URL derived from the function name */
    #[PatchAction()]
    public function patchMoreStuff()
    {
    
    }
    
    /** DELETE /dashboard/{item}/delete - Autowired */
    #[DeleteAction('{item}/delete')]
    public function deleteAnItem(ItemModel $item)
    {
    
    }

}