1. Go to this page and download the library: Download ahmedalmory/joda-resources 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/ */
ahmedalmory / joda-resources example snippets
Route::resource('/users', 'UserController');
// any thing after "controllers" in namespace would be prefixed to view and route properties
// Ex. namespace App\Http\Controllers\Admin;
// View would be admin.user
// route would be admin.users
namespace App\Http\Controllers;
use AhmedAlmory\JodaResources\JodaResource;
use App\Models\User;
class UserController extends Controller
{
use JodaResource;
// model that will be used for crud operations
protected $model = User::class;
// JodaResources will try to find a model with the name User in App\Models, App\ or App\Model
// will be used in store and update validation in case storeRules or updateRules are not set
protected $rules = ['name' => ' /// optional
// will be plural of the name property (in kebab case in case more than one word) if not set in this example 'users'
protected $route = 'users';
// name of the model that will be used in returned routes after finishing the operation
// optional
protected $files = ['photo'];
// items will be uploaded from the request in case there is file with the same name
// files will be saved in /uploads/{pluralNameOfTheModel} with name {user_id}-{time}.{ext}
// ex uploads/users/1-1624479228.jpg
// file will be deleted automatically upon deleting the object
// true by default
prtected $filterQueryString = true;
// add custom query
public function query($query)
{
return $query->whereNotNull('another_filed')->get();
}
}
//methods will be provided
//index => will return view($view) with three variables, 'route' route of the resource to be used in actions, 'index' (all users) and plural name of the model in this example 'users' you can use either of them
//create => will return view($view.create)
//store => will save all cols from request then return to $route.index
//show => will return view($view.show ) with two variables, 'show' and name of the model in this example 'user' you can use either of them
//edit => will return view($view.edit) with tow variables, 'edit' and name of the model in this example 'user' you can use either of them
//update => will update all cols from request then return to $route.index
//destroy => will save all cols from request then return to $route.index