artisticre

Member Since 3 Years Ago

Experience Points
11,690
Total
Experience

3,310 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
21
Lessons
Completed
Best Reply Awards
0
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.

  • Community Pillar

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

Level 3
11,690 XP
Jun
11
2 days ago
Activity icon

Replied to Redirect After Email Verification

yes and I changed the route below but still goes to /home

<?php

namespace App\Http\Controllers;

use Illuminate\Auth\Events\Verified;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Http\Requests\VerifyEmailRequest;

class VerifyEmailController extends Controller
{
    /**
     * Mark the authenticated user's email address as verified.
     *
     * @param  \Laravel\Fortify\Http\Requests\VerifyEmailRequest  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(VerifyEmailRequest $request)
    {
        if ($request->user()->hasVerifiedEmail()) {
            return $request->wantsJson()
                ? new JsonResponse('', 204)
                : redirect()->(route('user.dashboard').'?verified=1');
        }

        if ($request->user()->markEmailAsVerified()) {
            event(new Verified($request->user()));
        }

        return $request->wantsJson()
            ? new JsonResponse('', 202)
            : redirect()->(route('user.dashboard').'?verified=1');
    }
}

Activity icon

Replied to Redirect After Email Verification

Something like this?

 $this->app->singleton(
            \Laravel\Fortify\Contracts\LoginResponse::class,
            \App\Http\Responses\LoginResponse::class,
            \App\Http\Controllers\VerifyEmailController::class,
            \App\Http\Controllers\EmailVerificationPromptController::class
        );
Activity icon

Started a new Conversation Redirect After Email Verification

Where would I change the redirect when the user clicks on the link in the email to verify account? Right now it goes to /home. I want it to go to /user/dashboard.

Activity icon

Started a new Conversation Same URI Different Named Routes

I have 7 routes with the same URI but different named routes. They don't work unless I change the URI. Is there a way to have the same URI in Laravel?

Route::get('/dashboard',[RegistrarController::class, 'getDashboard'])->name('registrar.dashboard')->middleware('auth','registrar','verified');
Route::get('/dashboard', [WebmasterController::class, 'getDashboard'])->name('webmaster.dashboard')->middleware('auth','webmaster','verified');
Route::get('/dashboard', [TeamController::class, 'getDashboard'])->name('team.dashboard')->middleware('auth','team','verified');
Route::get('/dashboard', [PastorController::class, 'getDashboard'])->name('pastor.dashboard')->middleware('auth','pastor','verified');
Route::get('/dashboard', [SponsorController::class, 'getDashboard'])->name('sponsor.dashboard')->middleware('auth','sponsor','verified');
Route::get('/dashboard', [PilgrimController::class, 'getDashboard'])->name('pilgrim.dashboard')->middleware('auth','pilgrim','verified');
Route::get('/dashboard', [UserController::class, 'getDashboard'])->name('user.dashboard')->middleware('auth','user','verified');

Jun
10
3 days ago
Activity icon

Replied to Laravel 8 Fortify Redirect Based On Roles Without Jetstream

OK I added all that Now I get and I do h

Route [registrar.dashboard] not defined.

Route::get('/dashboard', [RegistrarController::class, 'getDashboard'])->name('registrar.dashboard')->middleware('auth','verified');

Registrar Controller

<?php

namespace App\Http\Controllers\Registrar;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class RegistrarController extends Controller
{
    public function getDashboard()
    {
        return view('registrar.dashboard');
    }
}

Activity icon

Replied to Laravel 8 Fortify Redirect Based On Roles Without Jetstream

OK I changed the LoginResponse and took out intended. Here it is. Still redirects only to /home, If I delete the vendor copy of LoginResponse, it gives an error so it tells me somewhere it is not recognizing my new version of LoginResponse but I am not sure where to make the change.



<?php

namespace App\Http\Responses;

use App\Http\Contracts\LoginResponse as LoginResponseContract;

class LoginResponse implements LoginResponseContract
{
    /**
     * Create an HTTP response that represents the object.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function toResponse($request)
    {
        if (auth()->user()->hasRole('admin')) {
            return redirect()->route('admin.dashboard');
    
        if (auth()->user()->hasRole('blog')) {
            return redirect()->route('blog.dashboard');
        }

        if (auth()->user()->hasRole('editor')) {
            return redirect()->route('editor.dashboard');
        }
        
    }
}

Activity icon

Replied to Laravel 8 Fortify Redirect Based On Roles Without Jetstream

It seems like Laravel isn't recognizing my new LoginResponse.php. I added it to the AppServiceProvider but it still is logging in to /home regardless of what I have in the LoginResponse. Is there somewhere else I need to add it to?

Activity icon

Replied to Laravel 8 Fortify Redirect Based On Roles Without Jetstream

So I did that, thank you. But it still logs in as /home. This is what I am trying to do:

AppServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
        $this->app->singleton(
            \App\Http\Contracts\Contracts\LoginResponse::class,
            \App\Http\Responses\LoginResponse::class
        );
      
    }
}

LoginResonse.php



<?php

namespace App\Http\Responses;

use App\Http\Contracts\LoginResponse as LoginResponseContract;

class LoginResponse implements LoginResponseContract
{
    /**
     * Create an HTTP response that represents the object.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function toResponse($request)
    {
        // here i am checking if the currently logout in users has a role_id of 2 which make him a regular user and then redirect to the users dashboard else the admin dashboard
        if (auth()->user()->hasRole('admin')) {
            return redirect()->intended(config('admin.dashboard'));
        }

        if (auth()->user()->hasRole('blog')) {
            return redirect()->intended(config('blog.dashboard'));
        }

        if (auth()->user()->hasRole('editor')) {
            return redirect()->intended(config('editor.dashboard'));
        }
        
    }
}
Activity icon

Started a new Conversation Laravel 8 Fortify Redirect Based On Roles Without Jetstream

I am looking for a good tutorial or advice on how to redirect after authenticated based on roles in laravel 8 fortify without jetstream. I have found one that says to create a new LoginResonse.php in App\Http\Responses\loginresponse.php which I did but I am not sure where to register this new response because the tutorial I am using says to do it in Jetstreamserviceprovider but I am not using Jetstream. Any ideas?

Jun
09
4 days ago
Activity icon

Started a new Conversation How To Pass Validation Errors To Sweet Alert

I have sweet alert installed and working. It is passing the error. but not showing what the error is.

Edit Page

@extends('layouts.app')

@section('content')

<div class="container">
    <div class="row">
        <div class="col-md-10 offset-md-1">
            <div class="card">
                <div class="card-header">Edit User</div>
                <div class="card-body">
                <form action="{{ route('registrar.users.update',$user) }}" method="POST">
                <div class="form-group row">
                            <label for="name" class="col-md-2 col-form-label text-md-right">Name</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ $user->name }}" required autofocus>

                                @error('name')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="email" class="col-md-2 col-form-label text-md-right">Email</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ $user->email }}" required>

                                @error('email')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

               
               
               
                @csrf 
                @method('PUT')
                <div class="form-group row">
                            <label for="name" class="col-md-2 col-form-label text-md-right">Roles</label>
                            <div class="col-md-6">

                @foreach($roles as $role)
                       <div class="form-check">
                       <input type="checkbox" name="roles[]" value="{{$role->id}}"
                       @if($user->roles->pluck('id')->contains($role->id)) checked @endif>
                       <label>{{ $role->name}}</label>
                       </div> 


                @endforeach
                </div>
                </div>
                <button type="submit" class="btn btn-info btn-sm">Update</button>
                </form>

                
            </div>
        </div>
    </div>
    </div>
</div>
@include('sweetalert::alert')
@endsection

Edit Controller

public function update(Request $request, User $user)
    {
        
        $validator = Validator::make($request->all(), [
            'name' => 'min:3|max:255',
            'email' => 'email',
        ]);

        if ($validator->fails()) {
            Alert::error('error', $validator);
            return back();
        }
        
        
        
        $user->roles()->sync($request->roles);
        $user->name = $request->name;
        $user->email = $request->email;
        $user->save();
        return redirect()->route('registrar.users.index')->with('success','User updated successfully!');
    
    }

Activity icon

Started a new Conversation Call To A Member Function WithInput() On String

I don't know why I am getting this error.

 public function update(Request $request, User $user)
    {
        
        $validator = Validator::make($request->all(), [
            'name' => 'min:5|max:255',
            'email' => 'min:5|email|max:255',
            ],
           
        );
        
        if($validator->fails()) {
            return back()->with('error', $validator->messages()->all()[0]->withInput());
        }

        
        
        
        $user->roles()->sync($request->roles);
        $user->name = $request->name;
        $user->email = $request->email;
        $user->save();
        return redirect()->route('registrar.users.index')->with('success','User updated successfully!');
    
    }
Jun
08
5 days ago
Activity icon

Started a new Conversation Missing Required Parameter For Route

Not sure how to fix this error!

Route

Route::prefix('registrar')->name('registrar.')->group(function() {
    Route::resource('/users', UsersController::class, ['except' => ['create', 'store', 'show']]);
});

Link to edit page

      <a href="{{ route('registrar.users.edit',$user) }}"><button type="button" class="btn btn-sm btn-primary">Edit</button></a>

Controller

 public function edit(User $user)
    {
        $roles = Role::all();
        $user = User::find($user);
        return view('registrar.users.edit',compact('user','roles'));
    }

Edit Page Form Route

 <form action="{{ route('registrar.users.update',$user) }}" method="POST">
                @csrf 
                @method('PUT')
                @foreach($roles as $role)
                       <div class="form-check">
                       <input type="checkbox" name="roles[]" value="{{$role->id}}">
                       <label>{{ $role->name}}</label>
                       </div> 


                @endforeach
                
                </form>
Jun
03
1 week ago
Activity icon

Replied to RoleUserSeeder Help

in the user seeder I have for instance team as a user. then in roles table I have a team role. in the roleuser seeder I am not attaching those correctly I know. It just assigns random roles to team

Activity icon

Started a new Conversation RoleUserSeeder Help

I have this roleuserseeder that is assigning random roles to users. How can I change this to assign a certain role to each user?

RoleUserSeeder

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Role;
use App\Models\User;

class RoleUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $roles = Role::all();

        User::all()->each(function ($user) use ($roles){
            $user->roles()->attach(
                $roles->random(1)->pluck('id')
            );
        });
    }
}

UserSeeder

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;
use DB;
use Hash;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('users')->insert([
            'name' => 'Registrar',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'Webmaster',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'Team',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'Sponsor',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'Pastor',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'Pilgrim',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);

        DB::table('users')->insert([
            'name' => 'User',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
        ]);
    }
}

RoleSeeder

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Role;
use DB;

class RoleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
       DB::table('roles')->insert([
           'name' => 'Registrar'
       ]);

       DB::table('roles')->insert([
        'name' => 'Webmaster'
       ]);

       DB::table('roles')->insert([
        'name' => 'Team'
       ]);

       DB::table('roles')->insert([
        'name' => 'Pastor'
       ]);

       DB::table('roles')->insert([
        'name' => 'Sponsor'
       ]);

       DB::table('roles')->insert([
        'name' => 'Pilgrim'
       ]);

       DB::table('roles')->insert([
        'name' => 'User'
       ]);



    }
}

Activity icon

Replied to What Does This Error Mean?

I think this is what you are saying. I forgot to return $user; in CreateNewUser.php

<?php

namespace App\Actions\Fortify;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\CreatesNewUsers;

class CreateNewUser implements CreatesNewUsers
{
    use PasswordValidationRules;

    /**
     * Validate and create a newly registered user.
     *
     * @param  array  $input
     * @return \App\Models\User
     */
    public function create(array $input)
    {
        Validator::make($input, [
            'name' => ['required', 'string', 'max:255'],
            'email' => [
                'required',
                'string',
                'email',
                'max:255',
                Rule::unique(User::class),
            ],
            'password' => $this->passwordRules(),
        ])->validate();

       $user =  User::create([
            'name' => $input['name'],
            'email' => $input['email'],
            'password' => Hash::make($input['password']),
        ]);

       return $user;  //Forgot this
    }
}

Activity icon

Started a new Conversation What Does This Error Mean?

I am using Laravel 8 and Fortify. When I try to register a new user I get the following. What does this mean?

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given
Activity icon

Replied to Need Opinion - UpdateUserProfileInformation.php

This is what I have. It works before I added the new fields but once the new fields are in, it won't update.

UpdateUserProfileInformation.php

<?php

namespace App\Actions\Fortify;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;


class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
    /**
     * Validate and update the given user's profile information.
     *
     * @param  mixed  $user
     * @param  array  $input
     * @return void
     */
    public function update($user, array $input)
    {
        Validator::make($input, [
            'name' => ['required', 'string', 'max:255'],
            'email' => [
                'required',
                'string',
                'email',
                'max:255',
                Rule::unique('users')->ignore($user->id),
            ],
            'address' => 'required|string|min:4|max:255',
            'apt' => 'required|max:255',
            'city' => 'required|string|min:4|max:255',
            'state' => 'required|string|min:4|max:255',
            'zipcode' => 'required|string|min:4|max:255',
            'phone' => 'required|string|min:4|max:50',
            'mobile' => 'required|string|min:4|max:50',
            'homechurch' => 'required|string|min:4|max:255',
            'churchcity' => 'required|string|min:4|max:255',
            'pastor' => 'required|string|min:4|max:255'
        ])->validateWithBag('updateProfileInformation');

        if ($input['email'] !== $user->email &&
            $user instanceof MustVerifyEmail) {
            $this->updateVerifiedUser($user, $input);
        } else {
            $user->forceFill([
                'name' => $input['name'],
                'email' => $input['email'],
                
            ])->save();
           
        }
    }

    /**
     * Update the given verified user's profile information.
     *
     * @param  mixed  $user
     * @param  array  $input
     * @return void
     */
    protected function updateVerifiedUser($user, array $input)
    {
        $user->forceFill([
            'name' => $input['name'],
            'email' => $input['email'],
            'address' => $input['address'],
             'apt' => $input['apt'],
             'city' => $input['city'],
             'state' => $input['state'],
             'zipcode' => $input['zipcode'],
             'phone' => $input['phone'],
             'mobile' => $input['mobile'],
             'homechurch' => $input['homechurch'],
             'churchcity' => $input['churchcity'],
             'pastor' => $input['pastor'],
            'email_verified_at' => null,
        ]);

      

     

        $user->sendEmailVerificationNotification();
    }
}

Activity icon

Replied to Need Opinion - UpdateUserProfileInformation.php

The question is in UpdateUserProfileInformation, my form points to this file to update and is working as far as updating the username, email, password. Would it be better to add the additional fields in the user table as nullable and then update when created? I am not sure how to update in a user table and profile table with Fortify

Activity icon

Started a new Conversation Need Opinion - UpdateUserProfileInformation.php

I have everything working with new user with Fortify. I can update username and password and all but what I am trying to do is add fields as a profile. I have it entering a user_id in the profile table I made but with Fortify I am not sure where to add the function to update the new fields on submit. My UpdateUserProfileInformation.php or create a new function in ProfileController?

UpdateUserProfileInformation.php

<?php

namespace App\Actions\Fortify;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;


class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
    /**
     * Validate and update the given user's profile information.
     *
     * @param  mixed  $user
     * @param  array  $input
     * @return void
     */
    public function update($user, array $input)
    {
        Validator::make($input, [
            'name' => ['required', 'string', 'max:255'],

            'email' => [
                'required',
                'string',
                'email',
                'max:255',
                Rule::unique('users')->ignore($user->id),
            ],
        ])->validateWithBag('updateProfileInformation');

        if ($input['email'] !== $user->email &&
            $user instanceof MustVerifyEmail) {
            $this->updateVerifiedUser($user, $input);
        } else {
            $user->forceFill([
                'name' => $input['name'],
                'email' => $input['email'],
            ])->save();
           
        }
    }

    /**
     * Update the given verified user's profile information.
     *
     * @param  mixed  $user
     * @param  array  $input
     * @return void
     */
    protected function updateVerifiedUser($user, array $input)
    {
        $user->forceFill([
            'name' => $input['name'],
            'email' => $input['email'],
            'email_verified_at' => null,
        ]);

      

     

        $user->sendEmailVerificationNotification();
    }
}
Jun
02
1 week ago
Activity icon

Replied to If Statement Not Sure How To Go About It

This is perfect. One last thing, how would I add styles to this? If yes, green text, if no red text?

Activity icon

Started a new Conversation If Statement Not Sure How To Go About It

I am pulling the email_verfied_at date from the database. I would like it to display yes if there is a date and no if it is not verified. How would I go about doing this?

{{ $user->email_verified_at }}
May
25
2 weeks ago
Activity icon

Replied to I Am Trying To Learn Jetstream. I Have A Dashboard Template That Works For Most Things But When I Try To Do The Following But Remove I Get Undefined Variable Header. How Can I Remove The Header Component?

I have done this and I still get the header below the template header I am using. Want to remove the default header that jetstream gives and use the dashboard template I am using. If I remove all together, it removes the header but the buttons like update profile photo won't work

 <x-slot name="header">

</x-slot>
Activity icon

Started a new Conversation I Am Trying To Learn Jetstream. I Have A Dashboard Template That Works For Most Things But When I Try To Do The Following But Remove I Get Undefined Variable Header. How Can I Remove The Header Component?

I am trying to learn Jetstream. I have a dashboard template that works for most things but when I try to do the following but remove I get undefined variable header. How can I remove the header component?

@extends('admin.admin_master')
@section('admin')

<x-app-layout>
    <!-- <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Profile') }}
        </h2>
    </x-slot> -->

    <div>
        <div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
            @livewire('profile.update-profile-information-form')

            @if (Laravel\Fortify\Features::enabled(Laravel\Fortify\Features::updatePasswords()))
                <x-jet-section-border />
            
                <div class="mt-10 sm:mt-0">
                    @livewire('profile.update-password-form')
                </div>
            @endif

            @if (Laravel\Fortify\Features::canManageTwoFactorAuthentication())
                <x-jet-section-border />

                <div class="mt-10 sm:mt-0">
                    @livewire('profile.two-factor-authentication-form')
                </div>
            @endif

            <x-jet-section-border />

            <div class="mt-10 sm:mt-0">
                @livewire('profile.logout-other-browser-sessions-form')
            </div>

            <x-jet-section-border />

            <div class="mt-10 sm:mt-0">
                @livewire('profile.delete-user-form')
            </div>
        </div>
    </div>
</x-app-layout>
@endsection
May
20
3 weeks ago
Activity icon

Awarded Best Reply on WithTrash And Restore

I figured it out. I was passing the wrong variable

 <a href="{{route('restore.category',$category->id) }}" class="btn btn-info btn-sm">Restore</a>

should be

 <a href="{{route('restore.category',$trash->id) }}" class="btn btn-info btn-sm">Restore</a>
Activity icon

Replied to WithTrash And Restore

I figured it out. I was passing the wrong variable

 <a href="{{route('restore.category',$category->id) }}" class="btn btn-info btn-sm">Restore</a>

should be

 <a href="{{route('restore.category',$trash->id) }}" class="btn btn-info btn-sm">Restore</a>
Activity icon

Started a new Conversation WithTrash And Restore

I have an interesting thing going on. Not sure how to fix it. I delete something and then I have a button to restore. The button is passing the same ID no matter how many items are in the restore area. So when I restore it restores everything in the list instead of just the one ID.

restore button

 <a href="{{route('restore.category',$category->id) }}" class="btn btn-info btn-sm">Restore</a>

Route

Route::get('/category/restore/{id}', [CategoryController::class, 'Restore'])->name('restore.category');

Model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Category extends Model
{
 
    use SoftDeletes;

    protected $fillable = [
        'user_id',
        'category_name',
    ];

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }
}

Controller

public function Restore($id){
 
    $delete = Category::withTrashed()->findOrFail($id)->restore();
    return redirect()->back()->with('success','Category has been restored successfully!');

}
May
19
3 weeks ago
Activity icon

Started a new Conversation Toastr.js Not Working

I am using Laravel 8 with Jetstream. I am trying to add Toastr.js but it is not showing up. What am I missing?

app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }}</title>


        <!-- Styles -->
        <link rel="stylesheet" href="{{ mix('css/app.css') }}">
       <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.css">


        @livewireStyles

        <!-- Scripts -->
        <script src="{{ asset('js/app.js') }}"></script>

    </head>
    <body class="font-sans antialiased bg-light">
        <x-jet-banner />
        @livewire('navigation-menu')

        <!-- Page Heading -->
        <header class="d-flex py-3 bg-white shadow-sm border-bottom">
            <div class="container">
                {{ $header }}
            </div>
        </header>

        <!-- Page Content -->
        <main class="container my-5">
            {{ $slot }}
      
        </main>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>

<script>
@if(Session::has('message'))
var type = " {{ Session::get('alert-type','info') }}"
switch(type){
    
    case 'info':
    toastr.info( " {{ Session::get('message') }} " );
    break;

    case 'success':
    toastr.success( " {{ Session::get('message') }} " );
    break;

    case 'warning':
    toastr.warning( " {{ Session::get('message') }} " );
    break;

    case 'error':
    toastr.error( " {{ Session::get('message') }} " );
    break;

}
@endif
</script>
        @stack('modals')

        @livewireScripts

        @stack('scripts')
        
    </body>
</html>

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Category;
use App\Models\User;


class CategoryController extends Controller
{
    public function AllCat() {
        return view('admin.category.index');
    }

    public function AddCat(Request $request) {

        $validatedData = $request->validate([
          'category_name' => 'required|:categories|max:255',
        ],
        [
            'category_name.required' => 'Please enter valid category name',
            'category_name.max' => 'Category name less than 255 characters',
        ]
        );

        //  haven't finished the add function yet 
        
         $notification = array(
             'alert-type' => 'success',
             'message' =>'TEST'
         );
         return view('admin.category.index')->with($notification);
    }
}

May
17
3 weeks ago
Activity icon

Replied to RedirectTo Based On Role

This is what I get and still get the error

 public function redirectTo()
    {
        if(Auth::user()->hasRole('registrar')){
            return redirect()->route('registrar.dashboard');
            }

            if(Auth::user()->hasRole('webmaster')){
                return redirect()->route('webmaster.dashboard');
                }

            
        }
Activity icon

Replied to RedirectTo Based On Role

like this?

f(Auth::user()->hasRole('webmaster')){
                $this->redirectTo = route('webmaster.dashboard');
            }
Activity icon

Replied to RedirectTo Based On Role

I tried the following and still gives me the route not defined error

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    // protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectTo()
    {
        if(Auth::user()->hasRole('registrar')){
            $this->redirectTo = route('registrar.dashboard');
            return $this->redirectTo;
            }
            
            if(Auth::user()->hasRole('webmaster')){
                $this->redirectTo = route('webmaster.dashboard');
                return $this->redirectTo;    
            }

            if(Auth::user()->hasRole('user')){
                $this->redirectTo = route('dashboard');
                return $this->redirectTo;    
            }

     }
}

Activity icon

Replied to RedirectTo Based On Role

Laravel UI

Activity icon

Started a new Conversation RedirectTo Based On Role

I'm sure I am not doing this right and you all will comment on how messed up my code is but I am trying to learn. I am trying to log in based on role and redirect to a dashboard based on that role. Here is my redirect code below but the only one that works is the route('user.dashboard') The rest says the route is not found. I also included my routes

public function redirectTo()
    {
        if(Auth::user()->hasRole('registrar')){
            $this->redirectTo = route('registrar.dashboard');
            return $this->redirectTo;
        } else{

        if(Auth::user()->hasRole('webmaster')){
            $this->redirectTo = route('webmaster.dashboard');
            return $this->redirectTo;
        } else {
            if(Auth::user()->hasRole('team')){
                $this->redirectTo = route('team.dashboard');
                return $this->redirectTo;
            } else {
                if(Auth::user()->hasRole('pastor')){
                    $this->redirectTo = route('pastor.dashboard');
                    return $this->redirectTo;
                } else {
                    if(Auth::user()->hasRole('sponsor')){
                        $this->redirectTo = route('sponsor.dashboard');
                        return $this->redirectTo;
                    } else {
                        if(Auth::user()->hasRole('pilgrim')){
                            $this->redirectTo = route('pilgrim.dashboard');
                            return $this->redirectTo;
                        } else {
                            if(Auth::user()->hasRole('user')){
                                $this->redirectTo = route('dashboard');
                                return $this->redirectTo;
                            } 
                        }
                    }
                }
            }
        }
    }
    }
}

routes

Route::get('/dashboard','[email protected]')->middleware('can:manage-users')->name('registrar.dashboard');
Route::get('/dashboard','[email protected]')->middleware('can:manage-users')->name('webmaster.dashboard');
Route::get('/dashboard','[email protected]')->middleware('can:team')->name('team.dashboard');
Route::get('/dashboard','[email protected]')->middleware('can:pastor')->name('pastor.dashboard');
Route::get('/dashboard','[email protected]')->middleware('can:sponsor')->name('sponsor.dashboard');
Route::get('/dashboard','[email protected]')->middleware('can:pilgrim')->name('pilgrim.dashboard');
Route::get('/dashboard', '[email protected]')->middleware('can:user')->name('home.dashboard');


Activity icon

Replied to Add Profile After Registration Tutorial

I saw this and was trying to get it more eloquent. I know I am trying here. How would I do this eloquent?

$lastOperationUser = DB::table('policies')
                  ->join('users', 'users.id', '=', 'policies.user_id')
                  ->get();
Activity icon

Replied to Add Profile After Registration Tutorial

OK I got it inserting the id on registration. I think I did the query right but not sure how to display on blade

$profiles = Profile::get()
    ->where('users','user_id','=','profile.user_id');
   return view('profile.profile')->with('profiles',$profile');
{{ $profiles->users->name}} ---doesn't work

Relationship in users table

public function profile() {
return $this->belongsTo('App\Models\Profile');
Activity icon

Started a new Conversation Add Profile After Registration Tutorial

Does anyone know of a good tutorial on adding profile page after registration? I want the registration to input user id in profile table and this will create the profile page. Then they can edit details from that

May
12
1 month ago
Activity icon

Awarded Best Reply on Update Method Creating New Entry Instead Of Updating Old Entry

Nevermind. I got it. Was pointing the action on the form to a different route.

Activity icon

Replied to Update Method Creating New Entry Instead Of Updating Old Entry

Nevermind. I got it. Was pointing the action on the form to a different route.

Activity icon

Started a new Conversation Update Method Creating New Entry Instead Of Updating Old Entry

Why is this code creating a new entry? I can't figure it out.

public function update(Request $request, $id)
    {
        $team = Team::find($id);
   
        $this->validate($request, array(
            'name' => 'min:3|max:255',
            'title' => 'max:255',
            'image' => 'mimes:jpg,jpeg,png,gif |max:4096',
            'email' => 'email',
            'phone'=> 'max:25'
           ));

           
           $team->name = $request->input('name');
           $team->title = $request->input('title');
           
           $team->email = $request->input('email');
           $team->phone = $request->input('phone');
           $team->bio = $request->input('bio');
           if($request->image) {
               $image = $request->file('image');
               $filename = time() .'.'. $image->getClientOriginalExtension();
               $location = public_path('images/uploads/team/'. $filename);
               Image::make($image)->save($location);
               $oldFileName = $team->image;
               $team->image = $filename;
              Storage::delete('$oldFileName');
           }
           $team->update();
           Session::flash('success','Team Member Details Updated Successfully');
          return route('admin.teams.index');
    }
May
11
1 month ago
Activity icon

Replied to Image Validation And Upload Tutorials

THank you so much. This got rid of the .tmp extension

Activity icon

Replied to Image Validation And Upload Tutorials

I am so lost. I really don't understand what I am doing wrong. Everything is working fine except it still puts the temp file C:wamp64\tmp\phpxxxx.tmp in DB. When I pull in the request like $image = $request->file('image') and then dd($image) I get the following. Please can someone help me figure this out. Everything else is writing to DB correctly except the filename for the image

Illuminate\Http\UploadedFile {#1245 ▼
  -test: false
  -originalName: "ce.png"
  -mimeType: "image/png"
  -error: 0
  #hashName: null
  path: "C:\wamp64\tmp"
  filename: "php5203.tmp"
  basename: "php5203.tmp"
  pathname: "C:\wamp64\tmp\php5203.tmp"
  extension: "tmp"
  realPath: "C:\wamp64\tmp\php5203.tmp"
  aTime: 2021-05-11 20:39:03
  mTime: 2021-05-11 20:39:03
  cTime: 2021-05-11 20:39:02
  inode: 4785074604244482
  size: 2410741
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\wamp64\tmp\php5203.tmp"
public function store(Request $request)
    {
        $image = $request->file('image');
        dd($image);
       $this->validate($request, [
  
            'name' => 'required|min:3|max:255',
            'title' => 'required|max:255',
            'image' => 'required|mimes:jpg,jpeg,png,gif |max:4096',
            'email' => 'required',
            'phone'=> 'required|max:25',
            'bio' => 'required'

        ]);
     if($request->hasFile('image'))
    {
        $destination = 'images/uploads/team';
        if(File::exists($destination)){
            File::delete($destination);
        }
        $image = $request->file('image');
      
       
        $filename = time() .'.'.$image->getClientOriginalExtension();
     
        $img = Image::make($image)->resize(50,50);
        $img->save(public_path('/images/uploads/team/'. $filename));
        $newImage = $img;
      
    }
    $team = new Team;
    $team->name = $request->input('name');
    $team->title = $request->input('title');
    $team->image = $newImage;
    $team->email = $request->input('email');
    $team->phone = $request->input('phone');
    $team->bio = $request->input('bio');
    $team = Team::create($request->all());
        return redirect()->route('team.index')->with('success', 'Team Member has been created');

    }
Activity icon

Replied to Image Validation And Upload Tutorials

Yes I forgot to add the image validation. Thank you for the suggestions. This is what I have and still getting the C:\wamp64\tmp\php94DE.tmp as filename in DB

 public function store(Request $request)
    {
        
       $this->validate($request, [
  
            'name' => 'required|min:3|max:255',
            'title' => 'required|max:255',
            'image' => 'required|mimes:jpg,jpeg,png,gif |max:4096',
            'email' => 'required',
            'phone'=> 'required|max:25',
            'bio' => 'required'

        ]);
        
   
        $team = new Team;
        $team->name = $request->input('name');
        $team->title = $request->input('title');
        $team->email = $request->input('email');
        $team->phone = $request->input('phone');
        $team->bio = $request->input('bio');
       
     if($request->hasFile('image'))
    {
        $destination = $request->image->store('images/uploads/team');
        if(File::exists($destination)){
            File::delete($destination);
        }
        $image = $request->file('image');
        $filename = time() .'.'.$image->getClientOriginalExtension();
        Image::make($image)->resize(50,50)->save(public_path('/images/uploads/team/'. $filename));
    }
    $team = Team::create($request->all());
        return redirect()->route('team.index')->with('success', 'Team Member has been created');

    }
Activity icon

Replied to Image Validation And Upload Tutorials

It all works but when I save, the filename for the image saved in the database is

C:\wamp64\tmp\php94DE.tmp
public function store(Request $request)
    {
        
        $validatedData = $request->validate([
            'name' => 'required|min:3|max:255',
            'title' => 'required|max:255',
            'email' => 'required',
            'phone'=> 'required|max:25',
            'bio' => 'required'

        ]);
        
        $this->validate($validatedData);
        $team = new Team;
        $team->name = $request->input('name');
        $team->title = $request->input('title');
        $team->email = $request->input('email');
        $team->phone = $request->input('phone');
        $team->bio = $request->input('bio');
       
     if($request->hasFile('image'))
    {
        $destination = 'images/uploads/team/'.$team->image;
        if(File::exists($destination)){
            File::delete($destination);
        }
        $image = $request->file('image');
        $filename = time() .'.'.$image->getClientOriginalExtension();
        Image::make($image)->resize(50,50)->save(public_path('/images/uploads/team/'. $filename));
    }
    $team = Team::create($request->all());
        return redirect()->route('team.index')->with('success', 'Team Member has been created');

    }
Activity icon

Replied to Image Validation And Upload Tutorials

How did I do?

 public function store(Request $request)
    {
        
        $validatedData = $request->validate([
            'name' => 'required|max:255',
            'title' => 'required|max:255',
            'email' => 'required',
            'phone'=> 'required|max:25',
            'bio' => 'required'

        ]);
        
        
        
        
        $team = new Team;
        $team->name = $request->input('name');
        $team->title = $request->input('title');
        $team->email = $request->input('email');
        $team->phone = $request->input('phone');
        $team->bio = $request->input('bio');
       
       if ($request->file('image')->isValid()) {
            $image = $request->file('image');
    
            $filename = time() . '.' . $image->getClientOriginalExtension();
    
            Image::make($image)->resize(300, 300)->save( public_path('/images/uploads/team/' . $filename) );
    
        }
       $team = Team::create($request->all());
 
        return redirect()->route('team.index')->with('success', 'Team Member has been created');

    }
Activity icon

Started a new Conversation Image Validation And Upload Tutorials

I am looking for a good tutorial on how to upload input fields with image and validate it all. Can someone redirect()->me to a good one?

Thanks

Apr
28
1 month ago
Activity icon

Replied to Duplicate ID On Update

Thank you for the response. I am still learning. I get this code is a mess but I would really still like to finish the project. Not going to use it in production, just development. How would you change that line?

Activity icon

Replied to Duplicate ID On Update

I will look into those. In the mean time, is there any way you can help with duplicating ID's?

Activity icon

Replied to Duplicate ID On Update

Something on YouTube. Sorry its a mess

Activity icon

Started a new Conversation Duplicate ID On Update

I am trying to follow a tutorial. This is how I learn. So far its working except when I go back in to edit the data. When I submit it creates a new ID with the updated data. For instance, if I am updating category ID 1, when I hit submit, my categories page now has category ID 1 and category ID 2. I am not sure why. Would someone mind lending me your eyes to see if something isn't right?

public function addEditCategory(Request $request, $id=NULL)
    {

        if($id==""){
            $title = "Add Category";
            $category = new Category;
            $categorydata = array();
            $getCategories = array();
            $message = "Category added successfully!";
        } else {
            $title = "Edit Category";
            $categorydata = Category::where('id',$id)->first();
            $getCategories = Category::with('subcategories')->where(['parent_id'=>0,'section_id'=>$categorydata['section_id']])->get();
            
            $category = Category::find($id);
            $message = "Category updated successfully!";

        }

        if($request->isMethod('post')){
            $data = $request->all();
            
            $rules = [
                'category_name' => 'required|regex:/^[A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+([\ A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+)*/u',
                'section_id' => 'required',
                'url' => 'required',
                'category_image' => 'image',
            ];

            $customMessages = [
                'category_name.required' =>'Category Name is required',
                'category_name.regex' => 'Valid Category Name is required',
                'section_id.required' => 'Section is required',
                'url.required' => 'Category URL is required',
                'category_image.image' => 'Valid Category Image is required',
            ];
       
           $this->validate($request,$rules,$customMessages);
             
            if($request->hasFile('category_image')){
                $image_tmp = $request->file('category_image');
                if($image_tmp->isValid()){
                    $extension = $image_tmp->getClientOriginalExtension();
                    $imageName = rand(111,99999).'.'.$extension;
                    $imagePath = public_path('/uploads/admin/images/category_images/' . $imageName);
                    Image::make($image_tmp)->save($imagePath);
                    $category->category_image = $imageName;
                }
            }

            if(empty($data['category_discount'])){
                $data['category_discount']="";
            }

            if(empty($data['description'])){
                $data['description']="";
            }

            if(empty($data['meta_title'])){
                $data['meta_title']="";
            }

            if(empty($data['meta_description'])){
                $data['meta_description']="";
            }

            if(empty($data['meta_keywords'])){
                $data['meta_keywords']="";
            }
            if(empty($data['url'])){
                $data['url']="";
            }

  

            $category->parent_id = $data['parent_id'];
            $category->section_id = $data['section_id'];
            $category->category_name = $data['category_name'];
            $category->category_discount = $data['category_discount'];
            $category->description = $data['description'];
            $category->url = $data['url'];
            $category->meta_title = $data['meta_title'];
            $category->meta_description = $data['meta_description'];
            $category->meta_keywords = $data['meta_keywords'];
            $category->status = 1;
            $category->save();
            
            Session::flash('success',$message);
            return redirect('admin/categories');
           
        }

        $sections = Section::get();
        return view('admin.categories.add_edit_category')->with(compact('title','sections','categorydata','getCategories'));
    }
Apr
26
1 month ago
Activity icon

Replied to Object Of Class Illuminate\\View\\View Could Not Be Converted To Number

Copying the code I found the error

return view('admin.categories.append_categories_level')-with(compact('getCategories'));

needs to be

return view('admin.categories.append_categories_level')->with(compact('getCategories'));
Activity icon

Replied to Object Of Class Illuminate\\View\\View Could Not Be Converted To Number

CategoryController

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Category;
use App\Section;
use Session;
use Auth;
use File;
use Image;

class CategoryController extends Controller
{
    public function categories(){
        Session::put('page','categories');
        $categories = Category::get();
        // $categories = json_decode(json_encode($categories));
        // echo "<pre>";print_r($categories);die;
        return view('admin.categories.categories')->with('categories',$categories);
    }

    public function updateCategoryStatus(Request $request) 
    {
           
        if($request->ajax()){
                $data = $request->all();
                // echo "<pre>"; print_r($data);die;
                if($data['status']=="Active"){
                    $status = 0;
                }else{
                    $status = 1;
                }
                Category::where('id',$data['category_id'])->update(['status'=>$status]);
                return response()->json(['status'=>$status,'category_id'=>$data['category_id']]);
            }
    }

    public function addEditCategory(Request $request, $id=null)
    {
        if($id==""){
            $title = "Add Category";
            $category = new Category;
        } else {
            $title = "Edit Category";
        }

        if($request->isMethod('post')){
            $data = $request->all();
            
            $rules = [
                'category_name' => 'required|regex:/^[A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+([\ A-Za-z\x{00C0}-\x{00FF}][A-Za-z\x{00C0}-\x{00FF}\'\-]+)*/u',
                'section_id' => 'required',
                'url' => 'required',
                'category_image' => 'image|mimes:jpeg,jpg,png,gif,svg|max:2048',
            ];

            $customMessages = [
                'category_name.required' =>'Category Name is required',
                'category_name.regex' => 'Valid Category Name is required',
                'section_id.required' => 'Section is required',
                'url.required' => 'Category URL is required',
                'category_image.image' => 'Valid Category Image is required',
            ];
       
           $this->validate($request,$rules,$customMessages);
             
            if($request->hasFile('category_image')){
                $image_tmp = $request->file('category_image');
                if($image_tmp->isValid()){
                    $extension = $image_tmp->getClientOriginalExtension();
                    $imageName = rand(111,99999).'.'.$extension;
                    $imagePath = public_path('/uploads/admin/images/category_images/' . $imageName);
                    Image::make($image_tmp)->save($imagePath);
                    $category->category_image = $imageName;
                }
            }
            $category->parent_id = $data['parent_id'];
            $category->section_id = $data['section_id'];
            $category->category_name = $data['category_name'];
            $category->category_discount = $data['category_discount'];
            $category->description = $data['description'];
            $category->url = $data['url'];
            $category->meta_title = $data['meta_title'];
            $category->meta_description = $data['meta_description'];
            $category->meta_keywords = $data['meta_keywords'];
            $category->status = 1;
            $category->save();
            
            Session::flash('success','Category added successfully');
            return redirect('admin/categories');
           
        }

        $sections = Section::get();
        return view('admin.categories.add_edit_category')->with(compact('title','sections'));
    }

    public function appendCategoryLevel(Request $request)
    {
        if($request->ajax()){
            $data = $request->all();
            $getCategories = Category::where(['section_id'=>$data['section_id'],'parent_id'=>0,'status'=>1])->get();
            $getCategories = json_decode(json_encode($getCategories),true);

            return view('admin.categories.append_categories_level')-with(compact('getCategories'));
        }
    }
}

append_categories_level

<div class="form-group">
                  <label>Select Category Level</label>
                  <select name="parent_id" id="parent_id" class="form-control select2" style="width: 100%;">
                  <option value="0">Main Category</option>
                   @if(!empty($getCategories))
                        @foreach($getCategories as $category)
                            <option value="{{ $category['id'] }}">{{ $category['category_name'] }}</option>
                        @endforeach
                   @endif
                  </select>
  </div>

scripts.js

$('#section_id').change(function(){
          var section_id = $(this).val();
          $.ajax({
            headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
             type:'post',
             url: '/admin/append-categories-level',
             data:{section_id:section_id},
             success:function(resp){
                 $("#appendCategoriesLevel").html(resp);
             },error:function(){
                 alert("Error");
             } 
          });
      });