草庐IT

laravel-response

全部标签

php - Laravel - 如何在没有实例化对象的情况下调用静态函数

在Laravel(5.2)中有没有什么方法可以在自定义对象中调用静态和/或非静态函数,而不必在它使用的所有类中实例化引用对象?示例:我的类App\Helpers\Utilities.php具有公共(public)函数doBeforeTask()我在我的项目中使用这个方法来分配类,如果我可以调用Utilities::doBeforeTask()或Utilities->doBeforeTask()而不是创建我的Utilities对象的实例$obj=newUtilities(); 最佳答案 将您的方法定义为静态方法。并使用以下代码在任何地

php - 使用 DB::table() 或 Model::all() Laravel 的 Eloquent

我想知道为什么很多人使用$users=DB::table('users')->get();而不是$users=Users::all();在Laravel项目中?什么是原因?问候 最佳答案 您可以这样做,因为Model和DBfacade都实现了生成Builder实例的函数。https://laravel.com/api/5.2/Illuminate/Database/Eloquent/Model.htmlhttps://laravel.com/api/5.2/Illuminate/Database/Query/Builder.html

php - Laravel 将 Http 重定向到 Https

我们使用Laravel5。要将http连接重定向到https,请使用中间件HttpsProtocol。namespaceMyApp\Http\Middleware;useClosure;classHttpsProtocol{publicfunctionhandle($request,Closure$next){if(!$request->secure()&&env('APP_ENV')==='prod'){returnredirect()->secure($request->getRequestUri());}return$next($request);}}在我们的4个测试用例中,只有

php - 如何在子域上上传 laravel 项目?

我想在子域中托管一个laravel项目。首先,我创建了一个子域名注册。在publicm_html/registraion中,我上传了项目文件。但是当我在url上看到项目时,我只看到文件而不是我存储的项目。上传laravel项目有什么问题?谁能帮我查一下? 最佳答案 假设您正在使用cPanel创建子域。以下是为laravel项目设置子域所需的一般步骤。创建您的子域将您的laravel项目上传到子域主目录。上传所有文件后。更新您的子域文档根目录以指向public_html/registration/public/文件夹,您可以从cPan

php - 如何使用 Laravel 5.3 注销并重定向到登录页面?

我正在使用Laravel5.3并尝试实现身份验证系统。我使用phpartisan命令make:auth来设置它。我根据我的布局编辑了View并将其重定向到我的仪表板页面而不是主页(在设置中设置为默认值)。现在,当我尝试注销时,它抛出了这个错误NotFoundHttpExceptioninRouteCollection.phpline161我在routes/web.php中的代码是:Auth::routes();Route::get('/pages/superadmin/dashboard','HomeController@index');HomeController.phpmiddle

php - Laravel Collective HTML5 属性

如何传入HTML5属性,例如:必需、自动对焦...?我可以输入其他具有name="value"的属性,但不能输入仅包含一个单词的属性。 最佳答案 传递带有值的数组作为第三个参数(对于select作为第四个)参数:{!!Form::text('name',null,['required'=>true,'some-param'=>'itsValue','class'=>'some-class'])!!} 关于php-LaravelCollectiveHTML5属性,我们在StackOverf

php - Laravel 502 错误网关错误

我使用Laravel5.3和最新的Homestead设置。当我向我的API发出POST请求时,根据日志文件我得到了这个错误:2016/10/2912:44:34[error]776#0:*28recv()failed(104:Connectionresetbypeer)whilereadingresponseheaderfromupstream,client:192.168.10.1,server:loc.medifaktor,request:"POST/api/v1/mfusersHTTP/1.1",upstream:"fastcgi://unix:/var/run/php5-fpm

php - Laravel 多态关系 : Passing model to controller

我想使用一个Controller来保存我对多个模型的评论。所以我使用以下存储方法创建了CommentController:publicfunctionstore(Teacher$teacher,Request$request){$input=$request->all();$comment=newComment();$comment->user_id=Auth::user()->id;$comment->body=$input['body'];$teacher->comments()->save($comment);returnredirect()->back();}在我看来,我有:{

php - 如何 array_values laravel 集合?

我有一个来自image模型的搜索结果,$photo保存了$photo->type=='photo'的数据。$photo=$image->filter(function($photo,$key)use($path){if($photo->type=='photo'){$photo->url=$path.$photo->image;return$photo;}});这是$photo集合,有什么方法可以array_values()items数据吗?Collection{#352▼#items:array:3[▼2=>ImageBanquet{#349▶}3=>ImageBanquet{#35

php - Laravel 5.2 在寄存器中添加条款和条件

我想在我的注册验证表中添加条款和条件,但它不起作用。谁能帮我解决这个问题。查看has('terms')?'has-error':''}}">Agreewiththetermsandconditions@if($errors->has('terms')){{$errors->first('terms')}}@endif授权Controllerprotectedfunctionvalidator(array$data){returnValidator::make($data,['name'=>'required|max:255','company'=>'required|max:255',