草庐IT

php - 一些 Laravel 4 PSR-0 问题?

我注意到Laravel4正在使用一些PSR标准。我最近安装了SensioLabs工具php-cs-fixer,当我们想要遵循PHP编码标准时,它可以检测并修复大部分问题。我在我的裸Laravel4副本中执行了命令,这是日志。php-cs-fixerfixapp/!ClassUserin/home/javier/Code/laravel/app/models/User.phpshouldhaveatleastavendornamespaceaccordingtoPSR-0rules!ClassDatabaseSeederin/home/javier/Code/laravel/app/da

php - Laravel Restfull Controller 和路由 ajax/sync 请求

我正在寻找最有效的方法来处理ajax请求作为使用普通表单的同步请求。据我所知,有2种方法可以处理例如新的订单发布请求:选项1:Controller中的AJAX检查(为简单起见,省略了验证和保存)。//Checkifwearehandlinganajaxcall.Ifitisanajaxcall:returnresponse//Ifit'sasyncrequestredirectbacktotheoverviewif(Request::ajax()){returnjson_encode($order);}elseif($order){returnRedirect::to('orders/

php - 使用 Laravel Eloquent ORM 获取 GROUP BY 中的最新值

我试图了解Laravel的EloquentORM是如何工作的,并且正在查看以下MySQL查询:SELECTid,name,dateFROMtablenameGROUPBYnameORDERBYdateGROUPBY的使用总是返回name的最早值。有没有办法返回最新值? 最佳答案 尝试下面的代码,Tablename::select('id','name',DB::raw('max(date)aslatest_date'))->groupBy('name')->orderBy('latest_date')->get()

php - Laravel - call_user_func_array() 期望参数 1 是一个有效的回调

我收到这个错误:call_user_func_array()expectsparameter1tobeavalidcallback,class'Symfony\Component\HttpFoundation\LaravelRequest'doesnothaveamethod'url'我使用的代码是:路由.php:分数.php:classScores_ControllerextendsBase_Controller{public$restful=true;publicfunctionget_showscores(){//Imprimopantallacontabladeresultad

php - 在 Laravel 服务提供商中替换服务的最佳方法是什么?

我想将Laravel框架提供的一项服务替换为我自己的服务,该服务扩展了相同的Laravel服务。在这种特定情况下,我想交换BladeCompiler服务。Laravel提供的默认ViewServiceProvider是这样的:useIlluminate\View\Engines\BladeCompiler;useIlluminate\View\Engines\CompilerEngine;...publicfunctionregisterBladeEngine($resolver){$app=$this->app;$resolver->register('blade',function

php - 如何在 laravel 的 Eloquent ORM 中编写内部连接?

我有一个名为buildings和flats的表建筑表Building_Id|Building_Name|.......|Building_Owned_By|....平面表Flat_Id|Flat_Name|........|Fk_Building_Id|.....在我的模型中建筑classBuildingextendsEloquent{protected$primaryKey="Building_Id";protected$table='buildings';..............publicfunctionflat(){return$this->hasMany('Flat','

php - 除了 root 之外,Laravel 路由不起作用

我已经在这个问题上花费了好几个小时,希望能找到出路。我已经正确设置了laravel,创建了一个项目myapp我的route.php文件只包含Route::get('/',function(){returnView::make('hello');});Route::get('/users',function(){return'Users!';});当我运行时http://localhost/myapp/public/我正确获取了laravel起始页当我运行时http://localhost/myapp/public/users我明白了TherequestedURL/myapp/index

php - 为什么找不到 Laravel trashed() 方法>

我正在尝试在Laravel4.1中使用ElequentORM的软删除功能删除记录按预期工作,但是当我使用withTrashed()搜索结果然后使用trashed()检查它是否是软删除记录时,我收到以下错误CalltoundefinedmethodIlluminate\Database\Eloquent\Collection::trashed()这是我的代码。有什么建议吗?$product=Product::withTrashed()->where('url',Input::get("product_url.$key"))->where('prolist_id',$list->id)->

php - Laravel Eloquent : merge model with Input

我想知道如何将来自Input::all()的数据与模型合并并保存结果。澄清一下:我想做如下的事情:$product=Product::find(1);//EloquentModel$product->merge(Input::all());//ThisiswhatIamlookingfor:)$product->save(); 最佳答案 你应该使用更新方法:$product->update(Input::all());但我建议改用only方法$product->update(Input::only('name','type...')

php - Laravel 在创建 Eloquent 对象时从空值创建默认对象

我正在尝试将一个对象保存到我在网站上构建的游戏的数据库中,但我不断收到此错误:Creatingdefaultobjectfromemptyvalue这是我使用的代码:foreach($input['items']as$key=>$itemText){$item=($input['itemIDs'][$key]==='NA')?newGameItem():GameItem::find($input['itemIDs'][$key]);//ifupdatingthisitem,checkthatitisassignedtothisgameif(!is_null($item->game_id