Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

andiliang andiliang
5
Hi, I encounter some strange things when I try to store the login user information to a globel javascript object or just directly print inside the blade component. the auth()->user() object give me print out addtional relation {id: 2, name: "...
MaximL MaximL
1
Hello, not sure if this should go in Eloquent or Laravel. A given user can have zero, one or multiple tags. Which tags the user has chosen is stored in a pivot table. I currently use the sync function in the update function of my controller to store...
mstdmstd mstdmstd
2
Hello, In laravel 7 app I have request with several calc fields $forumThreads = ForumThread ::with('latestForumPost.creator') ->withCount('forumPosts') ->with('creator') ->getByForumId(...
ayazsarwar ayazsarwar
6
Hello guys, I have 5 tables below, I want to get all categories with eagerloading brands and their product counts associated with that category. my tables structure: Brands Table: id, name Categories Table: id, name, parent_id Products Table: id, n...
Renkisa Renkisa
4
Good evening, I am trying to get businesses that have the best rating and limit the result to 5, which is in my classic phpMyAdmin query working but in Laravel, it is not... Here is my function: public static function getTopRates() { $results...
apokall apokall
1
I installed in my project Spatie\Translatable. I created table with json column. I inserted record with value in name column {"ru": "Ремонт техники", "ua": "Ремонт техніки"} I try get...
MaximL MaximL
2
Hello there, My views displays tags with checkboxes, some of them are selected, others are not. I retrieve which tags are selected in my controller function and display selected checkboxes. I can also retrieve and show all tags with empty checkboxes,...
I have a Laravel project that contains pivot tables. I am having N+1 issues so I need to eager load the results. Does anyone have idea how to eager load pivot relations?...
fylzero replied
Solved
vilbur vilbur
11
Hi all! I ´m creating CRUD application with repository pattern and I would like to check, if model has some relationships. So I can display related models. But i cant find out, if there is some method how I can check if some relationship exists. Bec...
DDSameera DDSameera
3
User Model public function courses() { return $this->belongsToMany(Course::class); } public function meetings() { return $this->belongsToMany(Meeting::class)->withPivot('unique_join_url'); } Meeting...
mstdmstd mstdmstd
2
Hello, in my laravel 5.7 app I need to add table and reference in other table to created table. I made 2 migration files and migrate command runs ok but running rollback I have an error : $ php artisan migrate Migrating: 2020_03_08_162307_create_colo...
shiro_ shiro_
2
I am writing a query to get the correct product_id where $stock->orderProduct->product->generic_name is equal to $item. My relationships are: class Stock extends Miioj { public function orderProduct() { return $this->belon...
maniMz maniMz
1
I have an Imageable pivot table, and in my pivot table, I have a column called type. When I try to create a new query, how can I add that value for my pivot table in my query? SomeModel::factory()->hasImages(2,['public' => true])->create()...
maniMz replied
Solved
robertldeboer robertldeboer
0
I am running into an issue with factories with "deeply nested" relationships are not syncing or sequentially saving and so causing database errors when the factory is ran. All my factories except the "top level" factory run withou...
cosmic_learning cosmic_learning
1
I have One To One relationship between the models: ApiRequest and ApiResponse. This is part of my ApiRequest model : public function apiResponse() { return $this->hasOne('App\ApiResponse', 'request_id'); } public function...
Nakov replied
Solved
noelhostad noelhostad
3
Hi, I have a relationship for an employee record that needs to retrieve an hourly rate. This relationship looks like this: employees n:n employmentSchemes 1:n paySchemes 1:n paySchemeRules I have a start date held in $employee, I calculate $yearsServ...
mstdmstd mstdmstd
4
Hello, In laravel 7 app I have 2 related tables ForumThread: Schema::create('forum_threads', function (Blueprint $table) { $table->increments('id')->unsigned(); ... $table->integer('forum_id')->...
grozavule grozavule
3
I've been getting trounced by Eloquent lately. First, I tried to get the most recent timestamp per user_id and machine_id from a database table. My Eloquent model, VisualLogin, complained that the query didn't include the table's primary key, ROWID....
grozavule grozavule
1
How would I perform the same query using an Eloquent model? $subquery = DB::connection('vmfgtest') ->table('LOGINS') ->select('USER_ID', 'MACHINE_ID') ->selectRaw('MAX(LAST_ACTIVITY) as LAST_ACTIVITY')...
This warning bothered me for a long time when I generate and use migration files. Each class must be in a namespace at least one level(A top-level vendor name) via PSR-4:https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader...
Endy replied
Solved
cdiscla cdiscla
1
Hello, i would like to realize a sort of CMS using Laravel; i need to define dynamic tables and i would like to access table contents without a Model, table name should be something like 'table_xyz' but there would not be a model for it. Is there a w...
pratamatama pratamatama
2
I have one model called FieldReport. The model belongsTo a User, and also belongsToMany user. I want my user to be able to see their report as well as the tagged one. This is how It looks like on my current model User.php /** * Each user may have ma...
dlebedef dlebedef
6
What would be the best way to have this relation: Company User A company can have many users, a User belongs to one company and each company has a main contact (user). And by best way how should I structure the migration and relationships the two m...
umefarooq umefarooq
0
I am sharing folders and images with many to many morph. i am saving folder and images details in folder and images table. while sharing them saving basic info in share folder and folder and images id in morphed shareable table. i want to paginate bo...
Spot-up Spot-up
7
How to get tag name from tag slug? Controller: public function postsbytag($tagSlug) { // something like that: $tagName = getNameBySlug($tagSlug); $posts = Post::withAllTags([$tagName]) ->orderBy('title')...
Spot-up replied
Solved
Hi. I have a class in which i want to inject several dependencies, depending on context. In theory that would be a perfect fit for setter injection. How can i make it work in Laravel? If i write something like: public function setMailer(Mailer $maile...
udara_supun udara_supun
2
DB::select( DB::raw(" select student_id, body, created_at from student_activity sa where sa.id in (select max(id) from student_activity where activity_ty...
Been getting used to using relationships between the same model. Pages database table: pages Columns: id, parent_id, ... (bunch of relationship unrelated ones) class Page extends Model { ...(bunch of functions etc here)... public function paren...
Tikay replied
Solved
galengidman galengidman
3
I have 3 models: courses, lessons, and instructors. Each course hasMany lessons Each lesson belongsTo a course, and belongsToMany instructors Each instructor hasMany lessons This feels like it should be easy, but I can't figure out how to create th...
I would like to do the following: Product can have one Supplier. The Supplier contains some data like a name. Additionally there is a pivot-value that should be stored for Supplier that is assigned to Product (e.g. a delivery_service-string). Example...
grozavule grozavule
4
I'm trying to switch from Query Builder to Eloquent models. How can I make my model, VisualLogin, return the last activity per user id and machine id? Here is my Query Builder equivalent: $visualLogins = DB::connection('vmfg') ->table(...
GodziLaravel GodziLaravel
4
Hello, I have an error with this code bellow : case 'initialized': $eml = ($rule == 'or') ? $eml->orwhere( 'emls.created_at','=','emls.updated_at'...
NiloLeon NiloLeon
3
Hi i need to insert a sql function inside where. How can do it? Thx $compta = DB::table('refunds') ->select(DB::raw("AVG(DATEDIFF(date_liq, date_status)) AS avgliq, MONTH(date_status) as mese, YEAR(date_status) as anno")) ->w...
appyapp appyapp
8
I am working on an existing site developed using plain PHP and have started developing a section of the site using Laravel. I am new to Larvel and it's concepts and have some questions. I only have App/Users.php class in my app at the moment but ther...
socieboy socieboy
5
I'm getting this error when i do a query on the User model, the column notification emails is cast to array, so i don't really know what that means, any idea? Call to undefined cast [Array] on column [notification_emails] in model [App\Models\User]....
Create a New Discussion Button