PHP code example of yesccx / laravel-preparation
1. Go to this page and download the library: Download yesccx/laravel-preparation 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/ */
yesccx / laravel-preparation example snippets
php
declare(strict_types = 1);
namespace App\Http\Preparations;
use Yesccx\Preparation\BasePre;
use Yesccx\Preparation\Exceptions\PreparationException;
use App\Models\User;
class UserPre extends BasePre
{
/**
* @var User 用户信息
*/
public User $info;
/**
* 处理
*
* @throws PreparationException
*/
public function handle(Request $request, User $user)
{
if (empty($id = $request->get('id', 0))) {
return $this->fail('缺少id参数');
}
$info = $user->where('id', $id)->first();
if (empty($info)) {
return $this->fail('用户不存在');
}
$thi->info = $info;
}
}
php
class UserController
{
public function update(UserPre $Pre, UserRequest $request)
{
$user = $pre->info;
// Do something...
}
}