PHP code example of mitirrli / laravel-skeleton

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

    

mitirrli / laravel-skeleton example snippets


public function index(Request $request)
{
    $users = User::filter($request->all())
        ->with($request->relations())   // <---
        ->latest()
        ->paginate($request->get('per_page', 20));

    return $users;
}

use use App\Traits\Filterable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Filterable;

    protected $filterable = [
        'user_id', 'category_id', 'version', 
    ];
}

public function index(Request $request)
{
    $posts = Post::with($request->relations())
                ->latest()
                ->filter() // <---
                ->paginate($request->get('per_page'));

    return $posts;
}

public function filterTitle($query, $keyword)
{
    $query->where('title', 'like', "%{$keyword}%");
}

// App\Traits\QuietlySave
User::saveQuietly([...]); 
// or
// App\Traits\QuietlyUpdate
User::updateQuietly([...]); 
bash
$ php artisan migrate --seed

http://laravel-skeleton.test/api/posts?with=user:id,username&user_id=123&category_id=4
// &user_id=123&category_id=4