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

automica

Building APIs at Automica HQ

Member Since 2 Years Ago

Bristol, UK

Experience Points
267,660
Total
Experience

0 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
862
Lessons
Completed
Best Reply Awards
251
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 50
267,660 XP
Nov
27
12 hours ago
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir you have this:

<input type="text" id="skill_id" name="skill_id[]" class="form-control" value="{{ $skill->skill_name }}">

which is wrong.

if you need want to store the skill_id, the value needs to be

<input type="text" id="skill_id" name="skill_id[]" class="form-control" value="{{ $skill->skill_id }}">
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir its a different error to last time.

can you copy the actually error? The bit in the SQLSTATE box?

when you have done that, can you place a

dd($request->skill_id, $request->level);

in your controller above

$user->skills()->detach();

so I can see what you are trying to save?

Activity icon

Replied to Implementing Tracking Pixels.

you need to make a request and as such you need something with a src tag.

something like:

<img src="http://my-server.com/request.php?id=123456">

will do that.

but if the snippets are being served on your site anyway, why embed a image in the html snippet? you could just as easily at it in the main template, especially if you want to pass in the id of something dynamic.

Activity icon

Replied to Laravel 7 Ajax Get Only Information

@mit2 can you reformat your code with three backticks before and after each code block? makes it much easier to understand your problem.

Activity icon

Awarded Best Reply on Store Route Is Shown Instead Of Show, Until Refresh Page

so hitting:

/myprofile

will always return a view with either a team set up or a means for you to add a team.

if you don't have a team, you add one, then save it to:

 Route::post('/teamstore', [TeamController::class, 'store'])->name('team.store');

and when you are finished, you've added a team and then you redirect to

/myprofile.

perhaps your redirect isn't working?

try:

 return redirect()->route('user.profile.show');
Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir we're only talking about one pivot table aren't we? have a guess?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir

in that case, you need to add a column called 'level' on your pivot table.

and we're back to doing this:

$user->skills()->detach();
if ($request->skill_id) {
    foreach($request->skill_id as $key => $skill){
        $user->skills()->attach($skill, ['level' => $request->level[$key]]);
    }
}

and this:

public function skills()
{
    return $this->belongsToMany(Skill::class)->withPivot('level');
}
Activity icon

Replied to Store Route Is Shown Instead Of Show, Until Refresh Page

@< gdb >

How come my redirect wasn't working?

I think I gave you an incorrect bit of code for your redirect which was:

return redirect('user.profile.show')

should have been:

 return redirect()->route('user.profile.show');

why was a redirect is necessary instead of just return view('...

because you should never return a view for a POST method. POST / PUT deals with storing data.

Save your data and then redirect to a GET method to display it.

A GET should be idempotent, meaning you can continue to call the same route without it changing your resource.

A bit of reading for you regarding this: https://www.restapitutorial.com/lessons/idempotency.html

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir can you confirm if my suspicion is correct first please?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir you don't see the error again. its a different error to last time.

what are you trying to save on the skill_user relationship?

I would suspect you want

user_id| skill_id | level ?

so you can have a user with multiple skills and each skill has 1 level?

Activity icon

Replied to Store Route Is Shown Instead Of Show, Until Refresh Page

so hitting:

/myprofile

will always return a view with either a team set up or a means for you to add a team.

if you don't have a team, you add one, then save it to:

 Route::post('/teamstore', [TeamController::class, 'store'])->name('team.store');

and when you are finished, you've added a team and then you redirect to

/myprofile.

perhaps your redirect isn't working?

try:

 return redirect()->route('user.profile.show');
Activity icon

Replied to Store Route Is Shown Instead Of Show, Until Refresh Page

what does your UserController::show method look like?

surely you are passing $team into the blade from the controller?

Activity icon

Replied to Trait Collisions : I Have This Problem Only On The Server Side Not On My Local !

not sure how file permissions would influence a php error?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir ok. so you just want to do a normal join.

change to:

$user->skills()->detach();
if ($request->skill_id) {
    foreach($request->skill_id as $key => $skill){
        $user->skills()->attach($skill, ['skill_id' => $request->level[$key]]);
    }
}

and change your relationship back to:

public function skills()
{
    return $this->belongsToMany(Skill::class);
}
Activity icon

Replied to Trait Collisions : I Have This Problem Only On The Server Side Not On My Local !

@godzilaravel it may be due to the error handling you have set up and your remote php is running more strict.

https://www.php.net/manual/en/function.error-reporting.php

I would compare phpinfo() on both environments. TBH if you are getting an error, its best to fix it rather then suppress it.

a search on laracasts brings this topic.

https://laracasts.com/discuss/channels/laravel/fatalerrorexception-in-userphp-line-44-trait-method-can-has-not-been-applied-because-there-are-collisions-with-other-trait-methods-on-appuser

and this workaround.

https://github.com/romanbican/roles/issues/110#issuecomment-137824366

Activity icon

Replied to Store Route Is Shown Instead Of Show, Until Refresh Page

don't return the

user.profile.show

view

redirect to the show method

return redirect('user.profile.show')

I guess that show method has a $team being passed from the method into the view.

Activity icon

Replied to Trait Collisions : I Have This Problem Only On The Server Side Not On My Local !

@godzilaravel didn't you just say that your server was:

PHP 7.2.24-0ubuntu0.18.04.7 (cli) (built: Oct 7 2020 15:24:25) ( NTS )

which doesn't look like PHP 7.4 to me.

do you need to restart it to pick up the new php version?

Activity icon

Replied to Trying To Access Array Offset On Value Of Type Null

@oxbir

considering your relationship is:

public function skills()
{
    return $this->belongsToMany(Skill::class);
}

surely you want to do:

$user->skills()->detach();
if ($request->skill_id) {
    foreach($request->skill_id as $key => $social){
        $user->skills()->attach($social, ['skill_id' => $request->link[$key]]);
    }
}

i'm not sure about this working:

$user->skills()->attach($social, ['skill_id' => $request->link[$key]]);

working though. what are you referencing $request->link? surely it should be $request->level?

is this just some copy + paste issue? and you want to do:

$user->skills()->detach();
if ($request->skill_id) {
    foreach($request->skill_id as $key => $skill){
        $user->skills()->attach($skill, ['skill_level' => $request->level[$key]]);
    }
}

and your relationship should add the pivot column

public function skills()
{
    return $this->belongsToMany(Skill::class)->withPivot('skill_level');
}
Activity icon

Replied to Insert Html Element In Html String.

is the end tag always the same?

The simplest approach is to string replace:

$someString= str_replace("</tag>", "Something inserted</tag>", $someString);
Activity icon

Replied to Which Platform Is The Best To Sell A Laravel App / Script?

What makes your app something that you can sell?

Activity icon

Replied to Trait Collisions : I Have This Problem Only On The Server Side Not On My Local !

so you get an error with php 7.2 and not with php7.4.

best upgrade server to php7.4 then..

Activity icon

Replied to Store Route Is Shown Instead Of Show, Until Refresh Page

@< gdb >

if you are renaming routes, you need to clear the cache afterwards.

can you show the whole method that has:

 // Return view
        return redirect()->route('user.profile.show', ['team'=>$team]);

at the bottom of it?

with your user.profile.show route, you are passing a team argument but in your route:

  Route::get('/myprofile', [UserController::class, 'show'])->name('user.profile.show');

you aren't using the argument.

if you are getting your user from Auth, why are you passing team to it?

Activity icon

Replied to Get Method Laravel And API

@eliekhazzaka providing you are storing the path to the profile image on your user model, then

$image = Auth::user()->profile_image;
Nov
26
1 day ago
Activity icon

Replied to SQL Query

when you say 'not working' what do you mean?

Activity icon

Replied to Drag And Drop

what type of 'simple html components'? are you looking for some WYSIWYG editor for articles are after you trying to make custom dashboards?

Activity icon

Replied to After Schema:dump Running Migrate Results In Error

@drivez try

php artisan migrate:fresh

if you want to migrate from scratch again. This will completely recreate your tables.

Activity icon

Replied to $loop->index Messes Up The Other Foreach

@sshateri my suggestion was to make the keys in your language array not reliant on id but as a composite of the language and level

eg

$languages = [
'ENGLISH-HIGHER' => [ 'language_name'=>'English', 'proficiency_level'=>'Higher'],
'FRENCH-BASIC' => [ 'language_name'=>'French', 'proficiency_level'=>'Basic']
]

That gives you unique id's without worrying about the actual id from the database.

Nov
25
2 days ago
Activity icon

Replied to SQL Query

@fylzero Ive been mining the archive for interesting series. Even the old stuff is still good learning

Activity icon

Replied to $loop->index Messes Up The Other Foreach

@sshateri I'm still stuck with your video as I can't read arabic and don't know which bit you are clicking and the section that is updating.

WRT languages, this is a list of language names and their respective level? That would mean your array key could be a compound string of

$language_name.'-'.$language_level

and that would mean that you can check for duplication and we have unique identifier and decouples from saved id.

Regarding your data picker field issue, I've not used flatpickr so dont know how well it plays with livewire. What you are describing seems related to the library picking up that the DOM has refreshed.

Looking at livewire docs, https://laravel-livewire.com/docs/2.x/alpine-js -> theres a section covering building a datepicker component so it might be worth looking at that as a way to solve your issues.

Activity icon

Replied to Laravel Charts And Dashboard

@noblemfd

This charts package:

allows you to create charts using chartisan and will allow you to make them dynamic using livewire.

see the following lesson for how to:

Activity icon

Replied to SQL Query

@fylzero I guess you have ran out of lessons to watch :P Have you any more to go as I see you are well into 1800..

Activity icon

Replied to SQL Query

@hjortur17 this should do it.

$today = Carbon::now()->format('d/m/Y');

$garageToday = Booking::with('services')
    ->where('booking_type', 'service')
    ->where('dropOffDate', $today)
    ->whereHas('services', function (Builder $query) {
        $query->where('category', 'garage');
    })
    ->orderBy('dropOffTime')
    ->get();
Activity icon

Replied to $loop->index Messes Up The Other Foreach

@sshateri rather than pass in the position of the language in the array, wouldn't it be better to remove it by its id

eg

wire:click="removeLanguage({{ $language['id'] }}

that way irrespective of how your array is ordered, you'll be able to delete the correct one

public function removeLanguage($languageId)
{
	$this->languages = $this->languages->where('id', '!=', $languageId);
}
Activity icon

Replied to $loop->index Messes Up The Other Foreach

did you change:

wire:model="languages.{{ $loop->index }}.language_level"

too?

I'm having some trouble understanding whats going on in your screen recording due to the non-English labels.

Can you post your livewire component so I can see whats going on with both your add* methods?

Activity icon

Awarded Best Reply on Every Update Resets My App.css And App.js

@thecelebratedmrk what else did you run once you installed that package?

installing composer packages don't usually touch any of the asset folders. if you've ran any of the post installation commands

php artisan ui

then this will affect your assets.

Activity icon

Replied to $loop->index Messes Up The Other Foreach

@sshateri not quite sure how those two loops relate to each other, but if you want to circumnavigate the issue, just use an index in your foreach:

@foreach ($languages as $lindex => $language)
    <div class="card card-body mb-4" wire:key="{{ $lindex }}">

and

@foreach ($certificates as $cindex => $certificate)
   <div class="card card-body mb-4" wire:key="{{ $cindex }}">
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`acl`.`post_saved`, CONSTRAINT `post_saved_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)) (SQL: Insert Into `post_

@neeraj1005 for pivot tables, the convention us to use the singular name of both models you are joining, in alphabetical order. So in your case,

post_user

your relationship should be

 public function users()
    {
        return $this->belongsToMany( User::class, 'post_user', 'post_id', 'user_id')->withTimestamps();
    }

or if you are following conventions, you can do:

 public function users()
    {
        return $this->belongsToMany(User::class)->withTimestamps();
    }

As Post belongsToMany User. I guess your saved_posts are the equivalent of favorites.

to add a record, you should sync like you are doing:

$posts->users()->sync([$post_id]);

you only need to pass in the post_ids though.

see https://laravel.com/docs/8.x/eloquent-relationships#syncing-associations

WRT to foreign key issue, I would read down the section in https://laravel.com/docs/8.x/eloquent-relationships and follow convention as much as possible.

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`acl`.`post_saved`, CONSTRAINT `post_saved_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)) (SQL: Insert Into `post_

@neeraj1005 IIRC then you can give pass in a second argument to change the name of the key if it clashes.

eg

            $table->foreignId('post_id','fk_pu_post_id')->constrained();
            $table->foreignId('user_id','fk_pu_user_id')->constrained();
Activity icon

Replied to How To Load Blade File Using Ajax Jquery

@araw can you explain the steps you want to do to get this 'blade' onto your page?

I assume you have a button you want to click and when you do so, it loads some more data into the page you are currently on?

Activity icon

Replied to Clearing Redis Cache

@shiva you can call

Cache::flush();

to clear redis cache.

https://laravel.com/docs/8.x/cache#removing-items-from-the-cache

Activity icon

Replied to How To Make A Search / Filter Card, So That Other Pages Can Also Be Filtered

@marfino3028 can you reformat your original post with three back ticks before and after each code block.

Theres a lot you can do to tidy up that code which will make it easier to see whats going on.

Even just replacing:

    foreach ($product_array

    as $key => $value){
    ?>

<div class="product-item ml-3 mb-5 cardz" data-string="<?php echo $product_array[$key]["name"]; ?>">

for

    foreach ($product_array

    as $key => $value){
    ?>

<div class="product-item ml-3 mb-5 cardz" data-string="<?php echo $value["name"]; ?>">

would help.

The procedural PHP you are using with inline queries and html is pretty old-school. As we're in a Laravel forum, I must take the opportunity to recommend you learn this MVC framework.

Activity icon

Replied to Image Not Displaying After Reverting The Backup Project

@antonioniphon I know this isn't directly related to solving this issue, but to prevent in the future, you should use a version control system (VCS) such as git and create new branches when you do major work. This way you are working on a copy of your code and if it doesn't work out then you can revert the changes or throw the copy away completely.

When your work passes your success criteria, then you just merge your work into the main branch.

This always leaves you a working version, and cuts down on needing to keep back up copies of your work as you will be syncing your VCS with a remote location to store the changes.

BTW with your current issue, are you sure the image is actually in the directory you are trying to load it from? If you've reverted files then is it likely you've also reverted the avatars directory too?

Activity icon

Replied to How To Load Blade File Using Ajax Jquery

@araw something like this will render the html returned from a successful response into a specific div in your blade:

$.ajax({
    url: "/my-route",
    success: function (result) {
        $("#div1").html(result);
    }
});
Activity icon

Commented on Allow For Configuration Hooks

@ordago that was mentioned in the video, which is why @jeffreyway switched to using 404 response at the end of the lesson.