Skip to content
Advertisement

Tag: eloquent

How to print table data in Laravel 5.6?

in My Larvel 5.6 app I am working with mysql db. and in my application I have vehicle table with following columns, vehicles, and I am going to group all models of the table and printing here as My controller, my printing blade file is this, it is printing well as now I need print in-front of model name there

Explain Eloquent morphMany parameters

I am new to laravel, can someone explain to me the parameters of morphMany: Answer The MorphMany relationship has the following function signature: Where: $related (required): refers to the related model. e.g: User::class. $name (required): the name of the polymorphic relation, like commentable. $type (optional): customize the {relation}_type field to look up when doing a query. $id (optional): customize the

hasManyThrough laravel relation

I have three table below. hasManyThrough in Country::class model to get all products. I want products which are related to countries or one country: Answer The relation you’re describing best suits a many to many, which is usually written in Laravel as a belongsToMany on both sides. If you stick to Laravel’s naming conventions: Rename product_countries to country_product. In country_product

whereJsonContains Laravel 5.6 not working?

The eloquent query above seems to only work when there is a single item in the ‘players’ json array. The data stored in the database looks as follows: [1] vs [“1″,”2”] Is there a reason the whereJsonContains is only working when it sees [1] in the db but not when it sees [“1″,”2”] ? I am pretty new to Laravel

Sum price of one to many relation ship (laravel)

i have problem with one to many relation ship! So im try to sum product prices so here is what i mean: Model: Product.php Model: Orders.php So i want make smth like this: $var->product->price->sum(); My database if it needed: Orders: id product_id|user_id| |-|———-|——-| |1|1 |1 | | | | | And Products have only 4 columns: id,name,price,description I mean that:

Accessor for relation objects in Laravel

this is my Category model: and when i call it in route for get all object like this: it seems accessor not work and i can’t get ‘Foo’ in category’s media object Answer You can use withDefault(): When there is no result, it returns a Media instance with the given attributes.

Laravel 5.6 – User not getting authenticated

I have looked for days, but my user never gets authenticated when using the auth middleware. We don’t use the standard laravel way, but using the standard auth middleware to block access to a route group. (in this example the dashboards) The data is correct as it doesnt give any error message, but the user itself never gets authenticated. I’ve

Advertisement