eloquent

Filter eloquent

ⅰ亾dé卋堺 提交于 2020-03-05 03:11:26
问题 Im using laravel for a project i am wanting to create an endpoint which filters and searches a Film model and returns a collection of films that match the chosen filter options which will be Options, Location and Age Rating picked by the user. I have created a query with how i would initially join the tables in symfony(hopefully its correct) but im unsure on how i adjust this to be more Laravel or eloquent. Film Model public function location(): BelongsTo { return $this->belongsTo(Location:

Filter eloquent

怎甘沉沦 提交于 2020-03-05 03:05:48
问题 Im using laravel for a project i am wanting to create an endpoint which filters and searches a Film model and returns a collection of films that match the chosen filter options which will be Options, Location and Age Rating picked by the user. I have created a query with how i would initially join the tables in symfony(hopefully its correct) but im unsure on how i adjust this to be more Laravel or eloquent. Film Model public function location(): BelongsTo { return $this->belongsTo(Location:

Laravel 4 's all() method started to return Eloquent collection lately - why?

本小妞迷上赌 提交于 2020-03-04 23:07:16
问题 This is my controller: return View::make('home.listings') ->with('listings', Listing::all()); Previously, I checked it on views like this: (and it worked on all my projects) @if(!empty($listings)) //use foreach and show listings @else <h3>No listing is found.</h3> @endif This is my Listing model. class Listing extends Eloquent { public static $key = 'id'; protected $table = 'ilanlar'; public $timestamps = false; } Right now, it works when there is an entry in database. However, when there is

Laravel connection timeout when connecting to database

删除回忆录丶 提交于 2020-03-02 09:40:07
问题 I am moving an application from my development machine to a test server. When connecting to my local development mysql database everything works as expected. When attempting to connect to our test server, the requests time out after 45 seconds and a 500 error is returned. I tested that the servers can communicate and php can get results by using the basic mysqli php functionality, and results are returned as expected: // Create connection $conn = new mysqli($servername, $username, $password,

Laravel connection timeout when connecting to database

[亡魂溺海] 提交于 2020-03-02 09:39:30
问题 I am moving an application from my development machine to a test server. When connecting to my local development mysql database everything works as expected. When attempting to connect to our test server, the requests time out after 45 seconds and a 500 error is returned. I tested that the servers can communicate and php can get results by using the basic mysqli php functionality, and results are returned as expected: // Create connection $conn = new mysqli($servername, $username, $password,

How to dynamically build this query - Laravel/Lumen

主宰稳场 提交于 2020-02-25 05:42:48
问题 I have the following input from the user: array ( 'id_coretable' => 1, 'Internal_key' => 'UPDATED1', 'extensiontable_itc' => array ( 'description_itc' => 'UPDATED1', ), 'extensiontable_sysops' => array ( 'description_sysops' => 'UPDATED1', ), ) and its contents shall update the following model: array ( 'id_coretable' => 1, 'Internal_key' => 'TESTKEY_1', 'extensiontable_itc' => array ( 'description_itc' => 'EXTENSION_ITC_1', ), 'extensiontable_sysops' => array ( 'description_sysops' =>

How to dynamically build this query - Laravel/Lumen

倾然丶 夕夏残阳落幕 提交于 2020-02-25 05:41:13
问题 I have the following input from the user: array ( 'id_coretable' => 1, 'Internal_key' => 'UPDATED1', 'extensiontable_itc' => array ( 'description_itc' => 'UPDATED1', ), 'extensiontable_sysops' => array ( 'description_sysops' => 'UPDATED1', ), ) and its contents shall update the following model: array ( 'id_coretable' => 1, 'Internal_key' => 'TESTKEY_1', 'extensiontable_itc' => array ( 'description_itc' => 'EXTENSION_ITC_1', ), 'extensiontable_sysops' => array ( 'description_sysops' =>

How to use WITH clause in Laravel Query Builder

爱⌒轻易说出口 提交于 2020-02-25 04:18:43
问题 I have SQL query (see example). But I can't find a way how I can write it in Query Builder. Do you have any ideas how is it possible? WITH main AS ( SELECT id FROM table1 ) SELECT * FROM table2 WHERE table2.id IN (SELECT * FROM main) I want to get format like: $latestPosts = DB::table('posts') ->select('user_id', DB::raw('MAX(created_at) as last_post_created_at')) ->where('is_published', true) ->groupBy('user_id'); $users = DB::table('users') ->joinSub($latestPosts, 'latest_posts', function (

Laravel - Extending Model

淺唱寂寞╮ 提交于 2020-02-24 11:30:14
问题 I've created a BaseModel class, which extends from Model. It seemed like everything was working fine, but now I've run into a problem when saving. I'm overriding the save() method in this BaseModel. I'd just like to add some attributes to the model before saving. So I do that, then call return parent::save($options); . The method signature is still the same: public function save(array $options = []) . It appears to be grabbing the name of the BaseModel class for the table name when performing

Select, where JSON Array contains

假如想象 提交于 2020-02-20 07:06:45
问题 So in Laravel 5 there's the handy thing called JSON Where Clauses using MySQL's new ability to store and fetch JSON stored in a column: User::where('meta->colors', 'red')->get() would return all rows, where colors in the column meta would be set to red . Now let's say colors is not a string, but an array containing multiple colors ( colors => ['red', 'blue', 'green'] ). What would be an efficient way to retrieve all rows, where colors contains e.g. the value red ? 回答1: JSON_CONTAINS() does