草庐IT

eloquent

全部标签

php - Laravel 中自动删除相关行(Eloquent ORM)

当我使用这种语法删除一行时:$user->delete();有没有办法附加各种回调,例如自动执行此操作:$this->photo()->delete();最好在模型类中。 最佳答案 我相信这是Eloquent事件(http://laravel.com/docs/eloquent#model-events)的完美用例。您可以使用“删除”事件进行清理:classUserextendsEloquent{publicfunctionphotos(){return$this->has_many('Photo');}//thisisarecom

php - Laravel 中自动删除相关行(Eloquent ORM)

当我使用这种语法删除一行时:$user->delete();有没有办法附加各种回调,例如自动执行此操作:$this->photo()->delete();最好在模型类中。 最佳答案 我相信这是Eloquent事件(http://laravel.com/docs/eloquent#model-events)的完美用例。您可以使用“删除”事件进行清理:classUserextendsEloquent{publicfunctionphotos(){return$this->has_many('Photo');}//thisisarecom

php - 创建和更新 Laravel Eloquent

插入新记录或更新(如果存在)的简写是什么?where('metadataKey','=',2001)->first();if($shopOwner==null){//Insertnewrecordintodatabase}else{//Updatetheexistingrecord} 最佳答案 以下是“lucip”所指内容的完整示例:$user=User::firstOrNew(array('name'=>Input::get('name')));$user->foo=Input::get('foo');$user->save();

php - 创建和更新 Laravel Eloquent

插入新记录或更新(如果存在)的简写是什么?where('metadataKey','=',2001)->first();if($shopOwner==null){//Insertnewrecordintodatabase}else{//Updatetheexistingrecord} 最佳答案 以下是“lucip”所指内容的完整示例:$user=User::firstOrNew(array('name'=>Input::get('name')));$user->foo=Input::get('foo');$user->save();

php - 获取在 Laravel 3/4 中执行的查询

如何使用LaravelQueryBuilder或EloquentORM在Laravel3/4中检索原始执行的SQL查询?例如,像这样的:DB::table('users')->where_status(1)->get();或者:(posts(id,user_id,...))User::find(1)->posts->get();否则,至少如何将所有执行的查询保存到laravel.log? 最佳答案 Laravel4+NoteforLaravel5users:You'llneedtocallDB::enableQueryLog()be

php - 获取在 Laravel 3/4 中执行的查询

如何使用LaravelQueryBuilder或EloquentORM在Laravel3/4中检索原始执行的SQL查询?例如,像这样的:DB::table('users')->where_status(1)->get();或者:(posts(id,user_id,...))User::find(1)->posts->get();否则,至少如何将所有执行的查询保存到laravel.log? 最佳答案 Laravel4+NoteforLaravel5users:You'llneedtocallDB::enableQueryLog()be

关于 laravel:Eloquent 查询列表项可见性约束

Eloquentquerytolistitemsvisibilityconstraints我正在为一个Eloquent查询而苦苦挣扎。我的最终目标是列出任何人撰写的所有公开帖子,以及给定用户在给定出版物中撰写的私人帖子。例子:鉴于这3个帖子标题:标题1|用户ID:1|is_private:真标题:标题2|用户ID:2|is_private:假标题:标题3|用户ID:3|is_private:真userId1的输出应该是:标题1和标题2我最好的方法是:123456  $posts= Post::WHERE('publication_id',$publicationId)    ->WHERE('

关于 laravel:Eloquent 查询列表项可见性约束

Eloquentquerytolistitemsvisibilityconstraints我正在为一个Eloquent查询而苦苦挣扎。我的最终目标是列出任何人撰写的所有公开帖子,以及给定用户在给定出版物中撰写的私人帖子。例子:鉴于这3个帖子标题:标题1|用户ID:1|is_private:真标题:标题2|用户ID:2|is_private:假标题:标题3|用户ID:3|is_private:真userId1的输出应该是:标题1和标题2我最好的方法是:123456  $posts= Post::WHERE('publication_id',$publicationId)    ->WHERE('

关于 php:如何使用 Laravel 4 Eloquent 连接列?

HowtoconcatenatecolumnswithLaravel4Eloquent?我有一个名为tenantdetails的表,其中包含1Tenant_Id|First_Name|Last_Name|........我想通过MySQL的连接函数将First_Name和LastName作为一列检索。所以我在我的controller中写如下1$tenants=Tenant::orderBy('First_Name')->lists('CONCAT(`First_Name`,"",`Last_Name`)','Tenant_Id');但结果如下错误:1234567 SQLSTATE[42000]

关于 php:如何使用 Laravel 4 Eloquent 连接列?

HowtoconcatenatecolumnswithLaravel4Eloquent?我有一个名为tenantdetails的表,其中包含1Tenant_Id|First_Name|Last_Name|........我想通过MySQL的连接函数将First_Name和LastName作为一列检索。所以我在我的controller中写如下1$tenants=Tenant::orderBy('First_Name')->lists('CONCAT(`First_Name`,"",`Last_Name`)','Tenant_Id');但结果如下错误:1234567 SQLSTATE[42000]