eloquent Questions
7
Solved
I want to write a Laravel Migration auto increment ID as a primary key. I want to start this ID with a another value rather than 1. How can I do so ?
The migration up() function:
public function...
Initiation asked 3/2, 2020 at 14:39
4
Solved
So as the title says, how can I know if a field of a Model is a foreign key in Laravel ?
Supose I have a FK column called show_type_id and a model named Event and I want to know if there is a funct...
Cappella asked 1/10, 2020 at 10:45
4
I have a users table and a permissions table. It's a many-to-many relationship so I also have a users_permissions table with a user_id & module_permission_id column.
The user model has the fol...
Visitation asked 30/5, 2017 at 10:2
4
Solved
I have a simple set-up of Albums and Images, each album has many images. I can get all the data fine but I want to limit the returned number of images to 3. I have tried passing a closure like so:
...
11
Solved
I'm using laravel and trying to make an Authenthication with Laravel passport. So I've done it by looking on the docs and youtube but I got this error. this is my AuthController that I requested an...
Fisc asked 11/5, 2020 at 4:30
16
When updating my Post model, I run:
$post->title = request('title');
$post->body = request('body');
$post->save();
This does not update my post. But it should according to the Laravel ...
Virgulate asked 24/10, 2017 at 20:55
6
For several console commands, I have the need to change databases so all my eloquent commands and queries run on the correct db (and server).
Ive seen a few solutions, the simplest seems to be cha...
Hail asked 11/8, 2016 at 2:48
2
Solved
I want to add custom validation for one field in laravel nova resource file.
I have one field in db which is service_id in the service table and I have nova resource file for the same table. On cr...
Liverwort asked 19/3, 2019 at 16:59
3
Solved
I have the following code in my controller where I am trying to load all 'members'. Every member can have more than one phone number. Phone numbers are stored in a table called phone_numbers and ar...
6
I have a table that contains an enum field
CREATE TABLE `user_status` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`values` enum('on', 'off'),
PRIMARY KEY (`id`),
) ENGINE=InnoDB;
how can...
2
Solved
Can anyone please explain in detail what Eloquent's Model::query() means?
Heated asked 25/7, 2018 at 10:55
5
I have a Product model with a hasMany relationship
public function pricing()
{
return $this->hasMany('App\ProductPrice', 'prod_id', 'id');
}
I then get the relationship
Product::with('pr...
3
I have 3 tables:
articles
tags
article_tag
They are both many to many relationships with a pivot.
I need to query this to get all articles that have an array of tags:
Article::with('tags')-...
5
Solved
I am using an eloquent query to retrieve data from a table. The table columns look like this:
id started_at finished_at
1 2016-06-01 2016-06-30
2 2016-05-03 2016-05-28
What I want to do is, g...
3
I have an SQL query that looks like:
SELECT * FROM orders FORCE INDEX(order_type_index) WHERE `type` = 1
I can use query builder to recreate this:
DB::table(DB::raw('orders force index(orders_type...
7
Solved
Might not be a question specific to Eloquent collections, but it just hit me while working with them. Let's just assume we have a $collection object which is an instance of Illuminate\Support\Colle...
Nessy asked 3/9, 2013 at 12:52
6
Solved
I have ( or am trying to make ) this query in Laravel
The problem I have is with the $orThose
I want to query LIKE.
The data in that field can be many things, but there will always be a key work...
9
Solved
I have a piece of code like this:
$products = Product::all()
if ($search_value) {
$products = $products->where('name', 'LIKE', "%$search_value%");
}
$products = $products->orderBy('create...
3
Solved
Here is what I try to do:
$q = Question::where('id',$id -> id)->get();
$q[] = $q->push([ 'test' => true]);
dd($q);
This will output:
Collection {#220 ▼
#items: array:3 [▼
0 =>...
Leadsman asked 17/7, 2015 at 11:9
3
Solved
Please have a look at the following code:
$msgs = Message::where(function($query) use ($start,$end){
$query->whereBetween('created_at', array($start, $end));
})->orderBy('created_at', 'DE...
7
Solved
Having one Eloquent model, is it possible to get all its relationships and their type at runtime?
I've tried taking a look at ReflectionClass, but I couldn't find anything useful for this scenari...
5
Solved
Laravel Model allows two functions for inserting the values to the database table. They are
Create:
User::create(['id'=>1,'name'=>'stack']);
Insert:
User::insert(['id'=>2,'name'=>'ove...
5
Solved
Can someone show me how to write this query in Eloquent?
SELECT * FROM `projects` WHERE `id`='17' OR `id`='19'
I am thinking
Project::where('id','=','17')
->orWhere('id','=','19')
->get();...
Datnow asked 24/12, 2014 at 6:0
7
When you create a new column in a table you can use the ->after('column name') to dictate where it goes. How can I create a migration that re-orders the columns in the right order I want?
4
Solved
How can I (eloquently) cascade a soft delete in Laravel? So when there is a post with comments for example, where both tables have soft deletes. When I remove the post, I want to remove the comment...
Caryncaryo asked 20/9, 2022 at 13:32
1 Next >
© 2022 - 2025 — McMap. All rights reserved.