artisticre's avatar

Toastr Working Kinda

This is working and uploading the image. It is sending the toastr message if successful. Where I am running into trouble is when I try to upload an image not listed in mimes: such as webp . I am trying to see if the error message works. It goes back to the upload page but no toastr message. What am I missing?

 public function update(Request $request, $id)
    {
        
        $update = User::find($id);
    
       
        $this->validate($request, [
            'name' => 'max:255',
            'phone' => 'required|string|max:255',
            'email' => 'required|email',     
            'image' => 'image|mimes:jpg,jpeg,png,gif,svg|max:2048',
        ]);


        if($request->hasFile('image'))
        {
           
            $destination = 'backend/images/profile/'.$update->image;
            if(File::exists($destination)){
                
                File::delete($destination);
            }
            $image = $request->file('image');
            $filename = time() .'.'.$image->getClientOriginalExtension();
            Image::make($image)->save(public_path('backend/images/profile/'.$filename));
            $update->image = $filename;
       
        }
        $update-> update([

        'name' => $request->name,
        'phone' => $request->phone,
        'email' => $request->email,

    ]);
    
    if ($update instanceof User) {
        // toastr()->success('Profile has been saved successfully!');
        toastr()->success('Profile Data Updated Successfully');

        return redirect()->route('admin.profile.view');
    } else{

    toastr()->warning('An error has occurred please try again later.');

    return back();
}
    }
0 likes
6 replies
Snapey's avatar

how would it generate a toastr message on validation? You have no code to do this.

Are you using some package that says it will toast errors?

Snapey's avatar

Are you using some package that says it will toast errors?

Snapey's avatar

@artisticre I can't see anything in the documentation that suggests it supports validation errors, so you are probably out of luck with this package

Snapey's avatar

Try adding the following to the bottom of your master layout blade file.

    @if ($errors->any())
        @foreach ($errors->all() as $error)
            toastr["error"]("{{ $error }}", "Error")
        @endforeach
    @endif

Please or to participate in this conversation.