Farshad Farshad
0

laravel advance where query builder

I have an advance where query and need to set operation for that like below but it's not working $query->where(function($q) use($filt...
faridsilva faridsilva
5

Refactoring an sql sentence to eloquent style

Hello, I'm refactoring an old e-commerce site from plain PHP to Laravel 5.5. I have a list of products by categories and subcategories, which need to be filtered by brands....
r_duong89 r_duong89
5

I have some Faker factories that I need clarification on

I'm trying to seed my database full of data and I'm trying to relate them but I can't find the way to do it. I currently have 30 pages of anime/{anime}, each with 12...
baeckerman83 baeckerman83
1

Connect three tables?

Hi! How can I make a select of three tables? 1st table: fixtures with league_id 2nd table: leagues with countries_id 3rd table: country Now I want to select fixtures...
general general
15

Relationship between Users and Roles

Hi guys I finally managed to make middleware and login. Now I want to show all users from DB and show their roles (title of roles). How can I do this? I know it's po...
Eloquent
15
2165
cjustado cjustado
4

Tinker edit record

I want to change or edit the username and password of a user. I tried to use this in tinker $user = App\Models\User; $user->find(1); $user->username = 'newusername';...
Eloquent
4
1160
nhayder nhayder
3

what is the laravel way to keep on Maximum of 5 records on DB

Hi, i'm storing user IP on database every time he logs in to his account, Clearly that might exceed hundreds of records for each user. So as you might expect,...
mostafalaravel mostafalaravel
10

impossible to mass assignment only two fields even if it is added to protected fallible

Hello , here the User model and as you can see the first_name, last_name are in that array: /** * The attributes that are mass assignable....
Eloquent
10
119
jkdesign1 jkdesign1
1

Delete deeply nested relationships

Hi, I have a system set up with relationships like this poll-->hasMany-->questions-->hasMany-->choices. I was attempting to use the laravel...
utpal2015 utpal2015
3

n+1 nested eager loading

I am creating a category system on my app. My category.php file like this, <?php namespace App; use Illuminate\Database\Eloquent\Model; cl...
tapaskaro tapaskaro
1

Many To Many Relationship DB Seeder

Hi, I have scenario where user can belong to multiple companies. Based on each company it can have different roles. I have User, Company, Role models and it creates...
RomainB RomainB
3

hasMany(Child) and return $this->where() in Child model doesn't work

Hi. Why this works: class Post extends Model { public function comments() { return $this->hasMany(Comment::class)->where('accept...
sktklaus sktklaus
1

Eloquent avg on nested items

$status = Company::with('members', 'members.tasks', 'members.tasks.rating')->findOrFail(1); my ratings has a column score, how can I add the a...
jlmmns jlmmns
2

How to use chunkById with a custom order?

Hi all! Currently, it seems it's not possible to use chunkById with a custom order, other than by id. Has anyone of you figured out...

What is different or best practices

sometimes i am fall in confuse between this functions : User.php file public function post() { return $this->hasMany(Post::class); or return $t...
mabdullahsari mabdullahsari
4

How to add observable events and use in an observer

TL;DR - How do I register custom observable events from a trait and observe those from another via an observer instance? I created a global scope, c...
Aktheon Aktheon
2

Building request for input array

I've seen widely used this structure $a = Products::find(1)->accesses()->get() Can i somehow get relations for multiple rows or some condition. For some...
yacira yacira
8

Showing a collection with hasManyThrough relation

Hi! I have three models: Vehiculo, Conductor and Asignacion Here there are the relations: In Vehiculo.php public function asignacion() { return...
exSnake exSnake
4

Repeated Query or Wrong Model Implementation?

This is my relationships: "Slot" hasMany "SlotQueries" "SlotQuery" belongsTo "Slot" I have a table w...
exSnake exSnake
1

SELECT the Newest (latest) query FOREACH Location

I made a table where every SlotQueries will be wrote. A SlotQuery has ID,SLOT_ID,LOCATION_ID,ATT_DATE,CREATED_AT column in a certain "ATT_DATE" some...
ChristophAust ChristophAust
11

Querying relation existenece performance

Hello there, I am having some performance issues checking for relation existence in a model. I have the following scopes: public function s...
nhayder nhayder
2

How to chain eager load articles according to categories and subcategories

i have multiple widgets on the page i'm giving the user the ability to load articles according to his choice, by selecting category subcategory then hitting the submit but...
adavie adavie
5

Problem the sub-selects with SUM() and group by statement

Converting working SQL with sub-select and SUM() to Eloquent. In the past, using DB::raw('columnName')works, but not in this case. SELECT...
Sayn77 Sayn77
2

Request to retrieve attributes related to a product

Hello, I need help on a request and I do not know how to do it. Here are my tables: Families (id, ..) => relation hasMany attributes Attributes (id, .., fa...
nabilunfarhanun nabilunfarhanun
1

How to run query with model function?

So, I have a model for products of a website. In the model I use a function to calculate the price of the product. It is something like this, class Product e...
tylerssn tylerssn
2

Model not acknowledging new PDO settings

It turns out that in PHP 7.0 and up we have to manually configure PDO to not return the binary version of GUID. To implement the new PDO feature, I added setAttribue to my...
laracastsluvr laracastsluvr
11

Getting distinct rows from a model with relationships

Hi there, Is there a way in the following relationship to get some distinct values? I have 3 models, Categories, Products, and Brands Categories...
Eloquent
11
240

Migrating database to new structure and converting data.

We are planning a major database restructure and instead of "Create" all the migrations are "Alter"-ing already existing tables. For example:...
calin.ionut calin.ionut
8

how to sync attributes in a specific order ?

I have pivot table that saves the attribute_id and product_id When saving the product with attributes ($attributes) i get an array ex: array:4 [ 0 =...
MarlonV MarlonV
1

Sync to a pivot table

Goodmorning Guys, I have a little trouble synchronizing extra data to a pivot table. I have searched and tried different things, but I cannot figure it out. Who can...
zerodps zerodps
3

Trouble with Authentication / Laravel 5.6 MacOS

Hi all, i recently updated my users table primary key (ID), public function up() { Schema::create('users', function (Blueprint $table)...
mostafalaravel mostafalaravel
2

change index behavior if 'ids' parameters exists

Hello , I would like that index() method returns a list of 'IDs' if only the parameter 'IDs' exists. also I would like to know if this is a clean work ?...
RomainB RomainB
4

What is the best way to manage an unregistered visitor rating system? Token? IP?

Hi all, I want my website visitor to be able to tell me by two simple button if some post are 'Usefull' or 'Useless', like thumbs. I know some packages could do this...
munteanuserban munteanuserban
2

Fetch all products from more orders

Hi guys, I have 3 tables : Order, Product and User. I want to display all orders made by a user with all products. ( ex : Order details + list all products, Order de...
Create a New Discussion Button