eloquent

Count from each distinct date, fill in missing dates with zero

半城伤御伤魂 提交于 2019-12-24 03:50:42
问题 I'm trying to create an Eloquent query that gets the total number of posts made each distinct day, and if the date is missing, fill it in with a value of zero. For example, if my table looks like this: +----+---------------------+ | id | date | +----+---------------------+ | 1 | 2015-01-01 00:00:00 | | 2 | 2015-01-01 01:53:18 | | 3 | 2015-01-01 02:41:26 | | 4 | 2015-01-02 12:51:01 | | 5 | 2015-01-05 08:24:12 | +----+---------------------+ This would output: 2015-01-01 : 3 2015-01-02 : 1 2015

how to get list of users who are not under belongsToMany relation under a table in laravel?

谁说胖子不能爱 提交于 2019-12-24 03:46:09
问题 Consider the following case. we have the Users table and Tasks table. they are in relation with belongsToMany with table task_user . How to get the list of all users who are not under any task? i.e. their user_id is not at all under that given task or even in the task_user table. why I need this is because like this we can only provide a list of users who are yet to be assigned a task. the task will be assigned to users and not a single user at a time. Editing_____________ also how to filter

Distant HasManyThrough

大憨熊 提交于 2019-12-24 03:44:52
问题 I have four Models: User Client Store Opportunity The relationships are defined as such: User hasMany Client Client hasMany Store Store hasMany Opportunity User hasManyThrough Store, Client (this works) The problem is that I'm attempting to access the User->Opportunity relationship via built-in Laravel relationships, but it doesn't seem as if I can do it without a custom Query or an additional user_id column on the opportunities table to allow direct access (even though one can be inferred

Laravel Eloquent integration in Codeigniter

无人久伴 提交于 2019-12-24 03:35:24
问题 I am trying to use eloquent orm inside codeigniter. Following is my composer.json file "require": { "php": ">=5.5.0", "illuminate/database": "5.0" }, "autoload": { "classmap": [ "application/models" ] } In index.php file I have I added require 'vendor/autoload.php'; I have create Eloquent.php file in application/models to initiate eloquent <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $CI = & get_instance(); $config = $CI->db; $pdo = new PDO('mysql:host='.$config-

3 models relationship in Laravel 5

南笙酒味 提交于 2019-12-24 03:24:29
问题 I have 3 Models. Project {id, name} Platform {id, name} Version {id, value} One Project can have multiple Platforms and each Platform can have multiple Versions within a Project . I have the following table which relates the models: As you can see Project 6 has versions 1 and 3 on platform 1, while Project 8 has versions 1 and 2 on the same platform. I want to get all Projects' Platforms and versions of those Platforms depending on the Project. For example, I'd like to do App\Project::find(6)

PHP: Instantiating a class from a variable oddly fails

久未见 提交于 2019-12-24 03:12:53
问题 I'm trying to instantiate a class (a Laravel3 Eloquent model) by a variable, and I'm getting an error saying that the class is not found. When I hardcode the class name, though, it works just fine. (FYI, in the code below $contact_type is expected to either be Phone, Fax, or Email.) Here's what I'm playing with at the moment: foreach( $input AS $contact_type => $contact_info ) { foreach( $contact_info AS $data ) { $obj = new $contact_type( (array)$data); echo'<pre>Obj: ',print_r($obj),'</pre>

Laravel: Getting Session ID oddly truncates when using foreach

爷,独闯天下 提交于 2019-12-24 01:19:00
问题 So this is something a little weird... In Laravel 5.2, I'm trying to retrieve the id from the sessions database table. I'm using the default Sessions migration generated by Artisan. Session.php (Session Model, this is all I have): <?php namespace App; use Illuminate\Database\Eloquent\Model; class Session extends Model { protected $table = 'sessions'; } If I do $sessions = Session::where('user_id', Auth::user()->id)->get(); and look through the nested arrays using dd($sessions); , the full ID

Laravel 5 eager loading dropping leading zeros from foreign key

落花浮王杯 提交于 2019-12-24 01:17:41
问题 I believe that I've encountered a bug in how Laravel 5.3 handles eager loading when the foreign key is a string which contains zerofilled numbers. I have two models (using a mysql backend), School and Student . The id field in School is a string, and contains 5-digit numbers assigned by the state, which include leading zeros. Student BelongsTo School , and contains a school_id field which is defined identically to the id field in School . I have done some testing, and I'm finding that when I

laravel uuid not showing in query

为君一笑 提交于 2019-12-24 01:01:27
问题 I've a postgres database table that uses uuid's as its primary key, via the webpatser/laravel-uuid package, and 'readable' web ids via vinkla/hashids . When I query the database, if I dd() the response, I see the UUID in full, but if I simply return , I instead get an integer. Presume I've overlooking something obvious, so: Migration $table->uuid('id'); $table->string('web_id'); $table->primary('id'); Model public function store() { $data = [ 'id' => Uuid::generate(4)->string, 'web_id' =>

Laravel 5.2 | query many to many to one

守給你的承諾、 提交于 2019-12-24 00:59:45
问题 Currently I am working on a multi domain and language project where videos are reused with different titles and description. My tables that are relevant to this question with relations look like posts >- videos >- videos_tags -< tags id id id id domain_id video_id video_id tag_id Of course I have created the models: Post, Video and Tag with all the required relationships. The thing I am trying is to get all the posts by my Tag model and maintaining the pagination() functionality. I am able to