0 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to Recently Viewed Session Based
The first code what I gave you is about ids. If you have an array with ids then just use whereIn
$deals = Deal::whereIn('id', session()->get('deals.recently_viewed', []));
Replied to Laravel Form
@foreach($permission as $value)
<input type="checkbox" name="permission[]" class="form-control name" value="{{ $value->id }}" {{ in_array($value->id, $rolePermissions) ? 'checked' : '' }}>
@endforeach
Awarded Best Reply on Search Results Pagination Works Not
You need to append a query string q
to the url in pagination links
$posts = Post::where('title', 'like', $q = "%{$request->q}%")
->orWhere('description', 'like', $q)
->paginate(4)
->withQueryString();
Docs: https://laravel.com/docs/8.x/pagination#appending-query-string-values
Because you can see it here that it works.
Replied to WithCount Returning Null
It's not about where
, if you check only id
it;s better to use find()
or findOrFail()
If you need to get a collection then use where
$raterTypeSchools = RaterTypeSchool::withCount('raterLists')->where('column', 'something')->get();
Replied to WithCount Returning Null
$raterTypeSchool = RaterTypeSchool::withCount('raterLists')->findOrFail(1);
$raterTypeSchool->rater_lists_count;
Awarded Best Reply on Classic 404, Kind Of Solved It. What's Wrong With This?
You need to add this route
Route::get('services/deleted', '[email protected]')->name('services.deleted');
before
Route::get('services/{service}', '[email protected]')->name('services.show');
So your routes order should be
Route::get('services', '[email protected]')->name('services.index');
Route::get('services/create', '[email protected]')->name('services.create');
Route::post('services','[email protected]')->name('services.store');
Route::get('services/deleted', '[email protected]')->name('services.deleted');
Route::get('services/{service}', '[email protected]')->name('services.show');
Route::get('services/{service}/edit', '[email protected]')->name('services.edit');
Route::patch('services/{service}','[email protected]')->name('services.update');
Route::delete('services/{service}', '[email protected]')->name('services.destroy');
Replied to Recently Viewed Session Based
$dealIds = collect(session()->get('deals', []))->pluck('id');
if ($dealIds->contains($deal->getKey()) && $index = $dealIds->search($deal->getKey())) {
session()->pull("deals.{$index}");
}
session()->push('deals', $deal);
Awarded Best Reply on Php Artisan Route:list -> Route Is Not Listed (Laravel 5.5)
Oh ok, you have same uri contact
there in both routes. The second one replace the first one.
So change it
Route::get('contact', '[email protected]')->name('contact.index');
Route::get('contact'/create, '[email protected]')->name('contact.create');
Replied to Php Artisan Route:list -> Route Is Not Listed (Laravel 5.5)
Oh ok, you have same uri contact
there in both routes. The second one replace the first one.
So change it
Route::get('contact', '[email protected]')->name('contact.index');
Route::get('contact'/create, '[email protected]')->name('contact.create');
Awarded Best Reply on WhereDoesntHave
You forget to add use
to pass variable to the closure.
$post = Post::find(1);
return Category::whereDoesntHave('posts', function ($query) use ($post) {
$query->where('id', $post->id);
})->get();
Replied to WhereDoesntHave
You forget to add use
to pass variable to the closure.
$post = Post::find(1);
return Category::whereDoesntHave('posts', function ($query) use ($post) {
$query->where('id', $post->id);
})->get();
Replied to Target Class [1] Does Not Exist.
It doesn't matter if you have Laravel 8 or not. It's same on all Laravel versions.
The main point is the order of your routes.
https://laravel.com/docs/7.x/controllers#restful-supplementing-resource-controllers
Replied to Recently Viewed Session Based
Yes getKey()
returns just primary key of your table, usually an id.
If you want to do that, just add $deal
to the session, but then you need to use a collection to apply same logic in_array
, array_search
etc.
Awarded Best Reply on Recently Viewed Session Based
Don't use wildcard *
, be more specific to which view you want to add it.
View::composer([
'includes.interested.SOMETHING'
], InterestedComposer::class);
The code in the controller should be something like this
if (in_array($deal->getKey(), $deals = session()->get('deals.recently_viewed', []))) {
$index = array_search($deal->getKey(), $deals);
session()->pull("deals.recently_viewed.{$index}");
}
session()->push('deals.recently_viewed', $deal->getKey());
Replied to Target Class [1] Does Not Exist.
I think a problem is that you have other routes after resource controller
Docs: https://laravel.com/docs/8.x/controllers#restful-supplementing-resource-controllers
Replied to Recently Viewed Session Based
Don't use wildcard *
, be more specific to which view you want to add it.
View::composer([
'includes.interested.SOMETHING'
], InterestedComposer::class);
The code in the controller should be something like this
if (in_array($deal->getKey(), $deals = session()->get('deals.recently_viewed', []))) {
$index = array_search($deal->getKey(), $deals);
session()->pull("deals.recently_viewed.{$index}");
}
session()->push('deals.recently_viewed', $deal->getKey());
Replied to Search Results Pagination Works Not
You need to append a query string q
to the url in pagination links
$posts = Post::where('title', 'like', $q = "%{$request->q}%")
->orWhere('description', 'like', $q)
->paginate(4)
->withQueryString();
Docs: https://laravel.com/docs/8.x/pagination#appending-query-string-values
Because you can see it here that it works.
Replied to Recently Viewed Session Based
In the service provider where you register your composer add this to register method
But it probably doesn't cause that problem.
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(InterestedComposer::class);
}
And I guess you have to check existense of that id in deals.recently_viewed
, if it exists there you have to remove it and add it to the end.
Replied to Add Validation Rule (one Of Both Required)
You don't have to mark me again. I saw it. If I knew an answer I would reply to you.
Awarded Best Reply on How To Use Translation Inside Function In Model
This should work
return $now->diffInDays($this->ends_at) . trans_choice('day|days', $now->diffInDays($this->ends_at));
Replied to How To Use Translation Inside Function In Model
This should work
return $now->diffInDays($this->ends_at) . trans_choice('day|days', $now->diffInDays($this->ends_at));
Replied to How To Save Dynamic Form In Laravel?
I recommend to you use template engine, for example Handlebars. Instead of concating html in js.
Replied to Get Current Guard From A Middleware
Add ...$guards
to the handle method in your middleware
public function handle(Request $request, Closure $next, ...$guards)
{
// in $guards you have current guards
}
Replied to How To Save Dynamic Form In Laravel?
You have there an array, so it has to be like this
public function rules()
{
return [
'title.*' => 'required',
'link.*' => 'required',
];
}
Docs: https://laravel.com/docs/8.x/validation#validating-arrays
Replied to How To Save Dynamic Form In Laravel?
Where is a validation? Add it and you avoid this problems.
Replied to How To Get Only Specific Year In Laravel
@devhoussam123 I really don't know what you were thinking about when you had the correct answer in your question...
Replied to Add Validation Rule (one Of Both Required)
Just add nullable
and required_without
there.
'bannUntil' => 'nullable|required_without:permanentBan|date_format:d.m.Y H:i',
'permanentBan' => 'nullable|required_without:bannUntil|accepted',
Awarded Best Reply on How To Order By Relationship ?
@godzilaravel You need to add another join with alias name, because it's same table.
Certificate::select('certifications.*')
->join('users', 'users.id', '=', 'certifications.user_id')
->join('users as directors', 'directors.id', '=', 'users.director_id')
->orderBy('directors.first_name')
->get();
Replied to Can I Dive Into Laravel With Basic Php Knowledge
I would start with PHP journey and then go into Laravel journey
Replied to How To Order By Relationship ?
@godzilaravel You need to add another join with alias name, because it's same table.
Certificate::select('certifications.*')
->join('users', 'users.id', '=', 'certifications.user_id')
->join('users as directors', 'directors.id', '=', 'users.director_id')
->orderBy('directors.first_name')
->get();
Awarded Best Reply on Function For Subtract All Column Records?
$result = DB::table('table_name')->sum('star_value');
Just replace table_name
with your table from database.
Replied to Function For Subtract All Column Records?
$result = DB::table('table_name')->sum('star_value');
Just replace table_name
with your table from database.
Replied to How To Order By Relationship ?
You need to use joins for that
Certificate::select('certifications.*')
->join('users', 'users.id', '=', 'certifications.user_id')
->orderBy('users.first_name')
->get();
Replied to Are Route Resources Best Practice For My Application?
For API I'd use Route::apiResource
, it's without create and edit method.
Docs: https://laravel.com/docs/8.x/controllers#api-resource-routes
Replied to Collections 'remove' Method ?
@sr57 What do you want to say with a link to another thread?
Replied to Blade Checkbox Returns Null When Unchecked
@vincej I would use ternary operator instead of if
in checkbox.
<input type="checkbox" name="staff" value="1" {{ $child->staff ? 'checked' : '' }}>
Awarded Best Reply on Eager Loading Used But I Still Get So Many Queries
I guess you need to do nested eager loading
https://laravel.com/docs/8.x/eloquent-relationships#nested-eager-loading
You don't know a loop variable?
https://laravel.com/docs/8.x/blade#the-loop-variable
And those queries are not related to the code you showed.
Replied to Eager Loading Used But I Still Get So Many Queries
It has to be something else, because this code is correct.
public function index()
{
$jobs = Job::with(['company', 'location', 'category', 'tags'])
->orderByDesc('updated_at')
->where('active', 1)
->paginate(15);
return view('job.index', compact('jobs'));
}
@foreach ($jobs as $job)
{{ $job->title }}
{{ $job->company->name }}
{{ $job->location->name }}
@endforeach
Replied to Eager Loading Used But I Still Get So Many Queries
What do you have in job.index.blade.php
Because your main problem is locations
table. And in your code is nothing with that table.
Replied to Eager Loading Used But I Still Get So Many Queries
Seriously? How can we help you without code? Even in the OP you have different query...
Replied to Eager Loading Used But I Still Get So Many Queries
How I said Those queries are not related to the code you showed.
Replied to Laravel Blade How To Concatenate Youtube Iframe Youtube Id From Database In Blade
That key is real video.
<iframe width="580" height="360" src="https://www.youtube.com/embed/QRfj1VCg16Y"></iframe>
So
<iframe width="580" height="360" src="https://www.youtube.com/embed/{{ $key }}"></iframe>
Where is a variable where you have code from youtube, use your variable.
Earned once your experience points ranks in the top 10 of all Laracasts users.