时间:2021-07-01 10:21:17 帮助过:27人阅读
php参数的默认值
functionmakecoffee($type = "cappuccino")
{return"Making a cup of $type.\n";
}
echo makecoffee();
echo makecoffee(null);
echo makecoffee("espresso");
?>
输出
Making a cup of cappuccino.
Making a cup of .
Making a cup of espresso.
模型绑定 (Model Binding)
在RouteServiceProvider中,在boot方法里实现模型绑定
public function boot(Router $router)
{
parent::boot($router);
$router->model('users', 'App\User');
$router->model('goods', 'App\Good');
$router->model('categories', 'App\Category');
$router->model('tryClothes', 'App\TryRecord');
$router->model('carts', 'App\Cart');
$router->model('orders', 'App\Order');
$router->model('orderItems', 'App\OrderItem');
//
}
表单申请 (Form Request)
phpartisanmake:requestCreateArticleRequest
publicfunctionauthorize()
{returntrue;
}
publicfunctionrules()
{return [
'title' => 'required|min:3',
'body' => 'required',
'published_at' => 'required|date',
// 也可以使用数组//'published_at' => ['required', 'date'],
];
}
publicfunctionstore(Request $request){$this->validate($request, ['title' => 'required|min:3', 'body' =>'required', 'published_at' => 'required|date']);
Article::create($request->all());
return redirect('articles');
}
Article::create($request->all());
php storm laravel 代码提示
在特定文件夹中创建控制器
php artisan make:controller Console/ConsoleController
[ReflectionException]
Class App\Http\Controllers\console does not exist
参考资料
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了laravel陌生知识点快速学习一,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。