laravel @if or @isset show nothing or gives an exeption

I have made in laravel v.8. a database query (eloquent) that returns several columns. $wgName = Auth::user() ->join(‘wg_groups’, ‘users.wg_group_id’, ‘=’, ‘wg_groups.id’) ->get(); Now I want in my html view that the wg_name is displayed if it is set. I have tried the following four things: @if(isset($wgName->wg_name)) <h1>{{$wgName->wg_name}}</h1> @endif Here simply nothing is displayed @if(isset($wgName)) <h1>{{$wgName->wg_name}}</h1>… Read More laravel @if or @isset show nothing or gives an exeption

How to foreach categories from 3rd index from my database / Laravel?

I am issuing a problem with the following: I foreach-ed my categories from index 1 to 3 in my blade file. Code @foreach($categories->take(3) as $category) <ul> <li>{{$category->name}}</li> </ul> @endforeach But now I want to foreach second half of my categories from my database on the other ul list. How to do that..? Thanks:) >Solution :… Read More How to foreach categories from 3rd index from my database / Laravel?

Laravel form post data from placeholder value

I want to pass the data on a form placeholder without user input, want to know if that is possible… Below is my form in view @extends(‘layouts.app’) @section(‘content’) <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <form action="kind" method="POST"> @csrf <div class="form-group"> <label for="exampleFormControlInput1"><i style="color:#000" class="fa fa-user" style="font-size:24px"></i> Name</label> <input type="text" class="form-control" id="exampleFormControlInput1" name="name" placeholder="{{ auth()->user()->name… Read More Laravel form post data from placeholder value

PHP variable binding issue with html from controller for ajax response

Controller: $html = ""; $user_id = 10; $by = ‘By Aaron’; $getLedgerData = "getLedgerData(‘" . $user_id. "’,’" . $by . "’)"; $html .= "<a onclick=" . $getLedgerData . "></a>" print_r($html);die; // result shows: getLedgerData(’10’,’By Aaron’) When I passed $html to ajax response and set from there to a respected HTML tag. It will also seem… Read More PHP variable binding issue with html from controller for ajax response

data showing in single option instead of multiple option from json array

I have a JSON array in a JSON file looks like this: { "states": [ { "state": "Andhra Pradesh", "districts": [ "Anantapur", "Chittoor", "East Godavari", "Guntur", "Krishna", "Kurnool", "Nellore", "Prakasam", "Srikakulam", "Visakhapatnam", "Vizianagaram", "West Godavari", "YSR Kadapa"] } ] } and I am successfully able to load all states in the select element as a… Read More data showing in single option instead of multiple option from json array

Laravel – multiple select query

I want to pull data from two columns in my database table, I’m not very good at querying SQL. When I do this query I get this error: Expression #2 of SELECT list is not in GROUP BY clause and contains… What am I missing? My query: $top_orders = OrderItem::select(‘name’,’productId’, DB::raw(‘count(name) as total’))->groupBy(‘name’)->orderBy(‘total’,’desc’)->take(5)->get(); >Solution :… Read More Laravel – multiple select query

eager loading pass variable in withCount where condition

$user = 1; Forum::with([‘posts’ => function($query){ $query->withCount([‘comments => function($query){ $query->where(‘id_user’, $user); }]); }]) ->get(); How to pass the value of the $user variable to $query->where(‘id_user’, $user); $user is not working (appears underlined in red in the editor). >Solution : $user = 1; Forum::with([‘posts’ => function($query) use ($user){ $query->withCount([‘comments => function($query) use ($user){ $query->where(‘id_user’, $user); }]);… Read More eager loading pass variable in withCount where condition

How to invalidate a user sessions and cookies with user_id in laravel?

In my project admin need to invalidate user auth, and redirect user to login page after receiving the next request from user. For this operation, anything that authenticates the user must obsolete! but how ? Something like the following method : use App\Http\Controllers\Auth\authController; … authController::invalidateAuth($user_id); … >Solution : logout user you want to, by id:… Read More How to invalidate a user sessions and cookies with user_id in laravel?

Difference between save, fill, create in laravel eloquent

So i am new to laravel, I don’t know the difference between save, fill and create in laravel eloquent. can anybody describe it? >Solution : save() method is when you already assign a value to a model instance. for example $user = new User; $user->name = "anything"; $user->save(); dd($user); // {‘id’: 1, ‘name’: ‘anything’} save()… Read More Difference between save, fill, create in laravel eloquent

How to install google consent script for CMP banner?

window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag("consent", "default", { ad_storage: "Denied", analytics_storage: "Denied", wait_for_update: 1000 }); gtag(‘set’, ‘url_passthrough’, true); google consent mode isnt working i’m beginner here thanks in advance for help >Solution : use this one window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag("consent", "default", { ad_storage:… Read More How to install google consent script for CMP banner?