1. Go to this page and download the library: Download weapnl/laravel-junction 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/ */
weapnl / laravel-junction example snippets
// app/Http/Controllers/API/UserController.php
namespace App\Http\Controllers\API;
use Weap\Junction\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* The class name of the model for which the controller should implement CRUD actions.
*
* @var string
*/
public $model = User::class;
/**
* Define the relations which can be loaded in a request using "array" notation.
*
* @return array
*/
public function relations(): array
{
return [
'orders',
];
}
// app/Http/Controllers/API/UserController.php
namespace App\Http\Controllers\API;
use Weap\Junction\Http\Controllers\Controller; // Make sure to import the Controller class from the Weap/Junction package.
class UserController extends Controller
{
/**
* The class name of the model for which the controller should implement CRUD actions.
*
* @var string
*/
public $model = User::class;
/**
* The class name of Resource to be used for the show and index methods.
*
* @var string $resource
*/
public $resource = UserResource::class;
/**
* Define the relations which can be loaded in a request using "array" notation.
*
* @return array
*/
public function relations(): array
{
return [
'orders',
// Define all your relations here with should be accessible through the API.
];
}
public function relations()
{
return [
'user' => fn($query) => $query->isAdmin(),
'user.activities',
];
}
public $searchable = [
'id',
'name',
'orders.order_number',
];