用php artisan make:controller创建controller之后有一个show方法,
public function show($id=0)
{
$page=Page::find($id);
print_r($page);
}
如何设置ID必须为数字,除了在方法里面?
因为这是用于资源型的路由,不输ID不走show方法到index里面,若是我用于其他控制器的getShow($id),
这样要是没输id会报错,只能这样指定一个默认值来避免吗?getShow($id=0),
在API中有很多方法,该如何使用?
比如说http://laravel.com/api/5.1/Illuminate/Http/Request.html#method_ip
echo \Requst::ip(); 这么用报错了,能不用use引入吗?很多时候记不住
string ip()
Returns the client IP address.
Return Value
string
指定一个路由只能为数字之后用户输了不是数字的就报错了,怎么让其提示不存在的,或者跳转到指定页面
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee