eloquent

Laravel Eloquent - Working with an array of JSON objects

让人想犯罪 __ 提交于 2020-11-29 03:05:09
问题 I have an array of JSON objects within my database (as depicted by the image below) How do I search for a specific value within it? Say I want the record where the "ends_at" field is equal to "2018-11-24 08:00:00" I've tried using ->where('column->starts_at', '2018-11-24 08:00:00') or even tried ->whereJsonContains('column->starts_at', '2018-11-24 08:00:00'). Within the model I've cast the column to an array - am I missing something, or can this not be done? 回答1: Use this: ->whereJsonContains

Laravel Eloquent - Working with an array of JSON objects

半世苍凉 提交于 2020-11-29 03:04:55
问题 I have an array of JSON objects within my database (as depicted by the image below) How do I search for a specific value within it? Say I want the record where the "ends_at" field is equal to "2018-11-24 08:00:00" I've tried using ->where('column->starts_at', '2018-11-24 08:00:00') or even tried ->whereJsonContains('column->starts_at', '2018-11-24 08:00:00'). Within the model I've cast the column to an array - am I missing something, or can this not be done? 回答1: Use this: ->whereJsonContains

Nearby stores in Laravel

时光总嘲笑我的痴心妄想 提交于 2020-11-28 10:45:49
问题 i'm try to get neraby store in Laravel 5.1 I have geocoding parser that caluclate coorinate. But i have problem with haversine formulas. Basically i need that from table Aziende (Stores) given a lat, long e category passed trough url, fetch the nearby stores. I try with this code: $dove = Input::get('dove'); $categoria_id = Input::get('id_categoria'); // 4: check if any matches found in the database table if (!empty($dove)) { $response = \GoogleMaps::load('geocoding')->setParamByKey ('address

Insert data to a pivot table in laravel

◇◆丶佛笑我妖孽 提交于 2020-11-26 08:10:47
问题 I have 3 tables: posts , tags , post_tag . Each Post has many tags so I use hasMany method for them. But when I choose for example 3 tags in my dropdown list, I can't add them to post_tag and as the result I can't select and show each post's tags. My Post model: class Post extends Eloquent{ public function tag() { return $this->hasMany('Tag'); } } My Tag model: class Tag extends Eloquent{ public function post() { return $this->belongsToMany('Post'); } } And my postController : class

Insert data to a pivot table in laravel

三世轮回 提交于 2020-11-26 08:07:49
问题 I have 3 tables: posts , tags , post_tag . Each Post has many tags so I use hasMany method for them. But when I choose for example 3 tags in my dropdown list, I can't add them to post_tag and as the result I can't select and show each post's tags. My Post model: class Post extends Eloquent{ public function tag() { return $this->hasMany('Tag'); } } My Tag model: class Tag extends Eloquent{ public function post() { return $this->belongsToMany('Post'); } } And my postController : class