AO-IO

AO-IO

Member Since 11 Months Ago

Experience Points
1,550
Total
Experience

3,450 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
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 1
1,550 XP
13 Sep
1 week ago

AO-IO left a reply on OnDelete('cascade') Not Working ?

I don't know where was the problem :| but I cleared the cache and removed $table->engine = 'InnoDB'; it worked ... so weird

AO-IO left a reply on OnDelete('cascade') Not Working ?

i removed $table->engine = 'InnoDB'; and it worked :|

AO-IO started a new conversation OnDelete('cascade') Not Working ?

Hello

I'm using Laravel 5.8.

my migration :

    public function up()
    {
        Schema::create('category_emergency', function (Blueprint $table) {
            $table->bigInteger('emergency_id')->unsigned();

            $table->bigInteger('category_id')->unsigned();

            $table->foreign('emergency_id')->references('id')->on('emergencies')

                ->onDelete('cascade');

            $table->foreign('category_id')->references('id')->on('categories')

                ->onDelete('cascade');
            $table->engine = 'InnoDB';

        });
    }


when I delete a category it doesn't delete the emergency related to it?

I'm using belongToMany relationship.

I have tried to set the engine to InnoDB but not working

And it's not showing any kind of errors:.

Am I doing something wrong?

12 Sep
1 week ago

AO-IO left a reply on Custom Error Messages For Only Api For Cases Like Integrity Constraint Violations And All In Laravel 6

You can use unique validation rule for the email field.

OR if you want to show custom view or JSON response for the query errors you can do something like this in App\Execptions\Handler.php :


    public function render($request, Exception $exception)
    {
        if ( $exception instanceof \Illuminate\Database\QueryException ) {
            // show custom view
            //Or
            //return response()->json($exception);
        }
        return parent::render($request, $exception);
    }

AO-IO left a reply on Laracasts Coupons Codes?

sigh I guess I will wait till black Friday

09 Sep
1 week ago

AO-IO started a new conversation Laracasts Coupons Codes?

Are there any coupons? I searched in google but they are all expired.

are there any new ones?

Thanks

06 Sep
2 weeks ago

AO-IO left a reply on How To Fix Foreach Loop Printing Data Twice In Carousel Bootstrap 4

it turns out the problem is from my css.

AO-IO started a new conversation How To Fix Foreach Loop Printing Data Twice In Carousel Bootstrap 4

I'm looping through $slides which returns all slides in my DB.

the carousel is working just fine.

I have title and second title stored in my DB.

so when I loop I get the slide with the title ok. when I add another slide I get the last title and the second title of my last slide in the new one.

like this :

ScreenShot

returning all slides in a service provider:


 View::composer('main', function ($view) {
            $view->with('slides', Slide::all());
        });

my carousel :



<div id="myCarousel" class="carousel slide" data-ride="carousel">
   <ol class="carousel-indicators">
      @foreach($slides as $slider)
      <li data-target="#myCarousel" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
      @endforeach
   </ol>
   <div class="carousel-inner">
      @foreach($slides as $s)
      <div class="carousel-item {{ $loop->first ? 'active' : '' }} carousel-image" style="background-size: cover;">
         <picture>
            <source srcset="{{asset('images/slides/main/'.$s->slideshow)}}" media="(min-width: 1400px)">
            <source srcset="{{asset('images/slides/main/'.$s->slideshow)}}" media="(min-width: 768px)">
            <source srcset="{{asset('images/slides/main/'.$s->slideshow)}}" media="(min-width: 576px)">
            <div style="background-image:url('{{asset('images/slides/main/'.$s->slideshow)}}');" class="d-block w-100 img-fluid carousel-image"></div>
         </picture>
         <div class="container">
            <div class="carousel-caption  text-center  animated fadeInUp  d-flex flex-column h-100 align-items-center justify-content-center">
               <h1 class="display-4">{{$s->title_slide}}</h1>
               <p class="lead">{{$s->title_p}}</p>
            </div>
         </div>
      </div>
      @endforeach
   </div>
</div>


What am I doing wrong?

HELP

25 Aug
3 weeks ago

AO-IO left a reply on How To Collect (mathematically) Any Number That Enters The Database

I learned Laravel from outside Laracasts but still needs Jeffery's lesson :D

AO-IO started a new conversation How To Collect (mathematically) Any Number That Enters The Database

I don't know how to explain this in English but I will try my best.

I have a table called invoices and when a user does something a record is added to the table. which is called Amount. So I want to know is it possible to add all the records that enter the invoice table?

like :

AMOUNT 1 + AMOUNT 2 + AMOUNT 3 + Keeps going ...

And display the total.

I have no idea what to try and what to do. I never did something like this before

is it possible to accomplish this?

29 Jul
1 month ago

AO-IO left a reply on Route Not Defined?

the problem is gone once I updated the app using composer update

AO-IO left a reply on Route Not Defined?

Humm.. the route is not even showing in route:list.

I have the route under a group

AO-IO started a new conversation Route Not Defined?

Hello.

I'm trying to make a search on the same page in my admin dashboard.

here's what I did in my controller:


  public function search(){

        $q = Input::get ( 'q' );
        if($q != ""){
            $case = Case::where ( 'donation_title', 'LIKE', '%' . $q . '%' )->orWhere ( 'donation_story', 'LIKE', '%' . $q . '%' )->paginate (5)->setPath ( '' );
            $pagination = $case->appends ( array (
                'q' => Input::get ( 'q' )
            ) );
            if (count ( $case ) > 0)
                return view ( 'admin.cases.index' )->withDetails ( $case )->withQuery ( $q );
        }
        return view ( 'admin.cases.index' )->withMessage ( 'No Details found. Try to search again !' );


    }



my route :


 Route::post('/search/case','[email protected]')->name('admin.search_cases');


my from :


    <div class="container">
        <form action="{{route('admin.search_cases')}}" method="POST" role="search">
            {{ csrf_field() }}
            <div class="input-group">
                <input type="text" class="form-control" name="q"
                       placeholder="Search cases"> <span class="input-group-btn">
                    <button type="submit" class="btn btn-default">
                        <span class="la la-search"></span>
                    </button>
                </span>
            </div>
        </form>
    </div>

Im getting :


Route [admin.search_case] not defined. 

I checked the route list PHP php artisan route:list and I cant see it

PS: I tried to clear the cache and config nothing changed

any idea whats going on here?

14 Jul
2 months ago

AO-IO left a reply on Undefined Variable: Users

thanks, man. it's working .

AO-IO started a new conversation Undefined Variable: Users

Hello.

I'm using this package spatie-laravel-permission

to add roles and permissions to my website.

in my admin dashboard, I fetched all users and set a delete method.


 public function user_destroy ($id){

        $user_delete= User::findOrFail($id);

            $user_delete->removeRole($user_delete->getRoleNames());
            $user_delete->delete();
       

        return view('admin.users.index')->with('success','User is deleted');
    }


so using the code above does not remove the user and his role.

I get this error :


Return value of App\User::getStoredRole() must implement interface Spatie\Permission\Contracts\Role, instance of Illuminate\Support\Collection returned

i tried to use PHP detach() :


            $user_delete->roles()->detach();

It is actually working but I get this error :



Undefined variable: users (View: resources\views\admin\users\index.blade.php)


THE PHP $users is defined in the index view like this :


 public function mainUsers(){

        $users = User::latest()->paginate(5);
        return view('admin.users.index',compact('users'));

    }


I don't know what is the problem when I use PHP detach() the $users are defined and I get all the users on my index.

Any idea of how I can solve this problem:?

27 May
3 months ago

AO-IO started a new conversation Maintenance Mode / Only Admins Can Access The Website

hello

I want to make the access to the website if it's on maintenance mode for admins only

on all routes, not only admin routes.

I added in CheckForMaintenanceMode middleware a handle function :


    public function handle($request, Closure $next)
    {
        if ($this->app->isDownForMaintenance() && !auth()->check()) {
            throw new HttpException(503);
        }

        return $next($request);
    }

the auth system is only for admins so I checked if there is not user authenticated and the app is on maintenance mode.

it's not working :\

any idea how I can get this done?

23 Feb
6 months ago

AO-IO left a reply on Creating A Widget

@PHILIPDENYS - I have currencies I want to display it in a widget so other website or blogs can use it in their blog post or website.

22 Feb
6 months ago

AO-IO started a new conversation Creating A Widget

Hello.

I'm trying to create a small widget for currency prices.

I want to do something like this in an iframe :

 <script type="text/javascript" src="https://site.com/widget.php?country=us&currencies=EUR"></script>
                                       

how I can make something like this in Laravel? Any idea?

06 Dec
9 months ago

AO-IO left a reply on Flash Session After Sending Verification Email

@SUSTAINED - thanks for the reply but I tried to override registered method in register controller but it's not flashing any session :\

04 Dec
9 months ago

AO-IO started a new conversation Flash Session After Sending Verification Email

I'm using Laravel's default auth,

And I'm redirecting the user after the registration to /email/verify/

how I can flash a session after the sending the email? instead of redirecting to /email/verify page?

thanks

28 Nov
9 months ago

AO-IO left a reply on Remove Login Link When User Is LoggedIn

@LOSTDREAMER_NL - No, I'm not. :(

I was thinking of storing the logged in status in local storage and based on that value I can hide it on make it visible

maybe something like :

 window.Laravel= {!! json_encode([
            'isOnline'=>auth()->check()
        ]) !!};

in the header

is it good for production?

AO-IO left a reply on Remove Login Link When User Is LoggedIn

@REALRANDYALLEN - I can use the blade directives in .vue files?

AO-IO started a new conversation Remove Login Link When User Is LoggedIn

I'm using Vue-router and when I log in I want to replace the login link in the navbar with the logged-in username.

My navbar is another separate component.

the link in my navbar Component:

  <router-link to="/login"><a class="nav-link">Login</a></router-link>

after the user is logged in (Login.vue) :

 this.$router.replace('/');

how I can accomplish this?

thanks

19 Nov
10 months ago

AO-IO started a new conversation Application Structure Suggestion

I'm building an online course registration system.

So We have a course and a group, classRoom.

in each classroom, there is a group and in each course, there is more than 1 group.

What is the best relationbetween the 3?

AO-IO left a reply on Submit Radio Buttons

@realrandyallen it was a problem with the browser cache thanks

18 Nov
10 months ago

AO-IO started a new conversation Submit Radio Buttons

I have a form with radio buttons and a submit button.


     <div class="form-group text-center">
       <form action="{{ route('register_group') }}" method="POST">
             @csrf
           <p class="lead">
              choose group : 
                </p>
        <div class="btn-group btn-group-toggle" data-toggle="buttons">
          @foreach($c->group()->get() as $g)
          <label class="btn btn-primary">
          <input type="radio" name="g_id" id="option1" autocomplete="off" value="{{$g->id}}"  required>time {{$g->name}} 
          </label>
          @endforeach
        </div><br><hr>
        
        <input class="btn btn-primary"value="register in group" type="submit">
                            </form>
                        </div>


so the problem when I submit the form without selecting any radio button it gives me the 1st radio button value.

Any idea on how I can make the form submits only if I select a value?

14 Nov
10 months ago

AO-IO left a reply on Searching In BelongsToMany Relation

@NEILCARPENTER - There is no difference still the same result

AO-IO started a new conversation Searching In BelongsToMany Relation

Hello

I'm trying to search with course name in BelongsToMany relation :


    public function search(){

        $search = request()->search;
        $groups = Group::with('courses')->
        whereHas('courses', function($query) use ($search){
        $query->where('name', 'LIKE', "%$search%");
        })
        ->get();

        return response()->json($groups,200);
    
     }

The relation between App\Group And App\Course :


APP\GROUP

 public function courses(){
        return $this->belongsToMany('App\Course');
    }

App\Course

 public function groups(){
        return $this->belongsToMany('App\Group');
    }

But I'm getting all the courses no matter what I type :\

Any idea how I can make this query works (instead of showing all the courses)?

07 Nov
10 months ago

AO-IO left a reply on Display Created_at From Pivot

@TYKUS - I do have a withTimestamps() but I'm looking to get it from the query.

because I'm returning the $users to export it to excel


$users = $group->student()->select('user_id','name','phone')->get();
     
         return $users;

AO-IO started a new conversation Display Created_at From Pivot

Hello

I want to display created_at from a pivot group_user


$users = $group->student()->select('user_id','name','phone')->get();

I have a relation between App\Group And App\User (BelongsTomany)

I'm selecting the name and phone and I want to get the timestamps from the relation table

any idea?

06 Nov
10 months ago

AO-IO left a reply on Export To Excel

@tykus


SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous (SQL: select `id`, `group_user`.`group_id` as `pivot_group_id`, `group_user`.`user_id` as `pivot_user_id` from `users` inner join `group_user` on `users`.`id` = `group_user`.`user_id` where `group_user`.`group_id` in (2))

AO-IO left a reply on Export To Excel

it is a relation between App\Group and App\User

AO-IO left a reply on Export To Excel

@tykus I'm getting this error :

1052 Column 'id' in field list is ambiguous

using :


$group = Group::with('students:id,name,fullname')->findOrFail($id);

AO-IO started a new conversation Export To Excel

Hello

I'm using this package:LaraveExcel

https://github.com/Maatwebsite/Laravel-Excel

I'm trying to export excel with a relation.

so in my UserExport :


/**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        
     $group = Group::findOrFail($id);
    $students = $group->students()->where('group_id', '=', $group->id)->get();
  

    }

I'm trying to export students from the group.

the group and users have a relation.

so I want to get all users in the group.

and only certain columns like name and full name etc.

any idea on how I can accomplish this?

02 Nov
10 months ago

AO-IO started a new conversation Prevent Students From Registration

Hello

I have a small system which students can register for courses

the problem when someone is registered on a course, he can register in any course that has the same date lets say.

I have a date start and a date end for a course.

I register users using :


public function register($student, $course)
    {
       
        CourseRegister::create([
            'student'=>$student,
            'course'=>$course
            ]);
      
        
        return redirect()->back();
    }

How I can prevent students from registering in courses that have the same date?

29 Oct
10 months ago

AO-IO started a new conversation Get A Value From Relations

I have 3 models : Group Category Post

And I have a relation between the Post and the category:


 public function category(){
        return $this->belongsToMany('App\Category');  
}

public function post(){
        return $this->belongsToMany('App\Post');
    }

Pivot table :

ID | post_id | category_id

And I have a relation between group and post


class Group extends Model
{
    public function Posts(){
        return $this->belongsToMany('App\Post');
    }
}

class Post extends Model {
  public function groups(){

        return $this->belongsToMany('App\Group');
    }

}


is it possible to get the categories from the 1st relation using $group->category for example?

Any help is appreciated.

thanks

26 Oct
10 months ago

AO-IO left a reply on Attach Many Values Relations

@tykus I realized that I didn't make The <select> an array :D

thanks

AO-IO started a new conversation Attach Many Values Relations

I have a relation between posts and categories belongToMany relation.

so when I create a post I need to insert multiple values to the pivot table with the selected categories.

in my post controller ;

    public function store(Request $request)
    {
        $post = new Post;

        $post->name = $request->name;

        $post->save();


        $post->category()->attach(['category_id'=>$request->categories]);

        return redirect()->to(route('admin.posts.index'));
    }

I only get 1 value in the pivot table for the post

Any idea?

24 Oct
10 months ago

AO-IO left a reply on Updating User Roles

@lostdreamer_nl I was sending empty role_id field thats why i got the error

thanks

AO-IO started a new conversation Updating User Roles

Hello

I'm trying to update the user role using Vue.

So I made an API with the method update :


 public function update(Request $request, $id)
    {
        $user = User::findOrFail($id);

     $this->validate(request(), [
            'name'=>'string',
            'full_name'=>'string'
        ]);

        $user->name = $request->name;
        $user->full_name = $request->full_name;
        $user->roles()->sync([$request->input('role')]);
        
     
        $user->save();
    
       
        session()->flash('Done','updated');
        return response()->json('d',200);

}

And I'm getting this error :

 "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `role_user` (`role_id`, `user_id`, `0`) values (0, 1, 3))"

What Am I doing wrong?

21 Oct
10 months ago

AO-IO started a new conversation Editing Users Using VueJs

I'm having an issue where I can't get the id of the selected user in the table to pass it to Vue.

So my modal component is :

<admin-edit-modal :data-admin="admin.id"></admin-edit-modal>

I used props to get the id from the fetched data.

 created(){
          axios.get(`api/admins/edit/${this.dataAdmin}`,[
 
            ])
            .then(res=>{
              this.name = res.data.name;
              console.log(res)
            })
        },
         props: ['dataAdmin'],


My modal component is inside the v-for

when I open the modal I see the name of the first user always even I hit edit on the last user:.

I don't know if I'm getting the id in the correct way or not :\


 public function edit($id)
    {
       $admin = User::find($id);
        return response()->json($admin);
    }

my index() function is returning the index view which lists the users.

I'm really confused about this :\

Any help is appreciated

19 Oct
11 months ago

AO-IO started a new conversation Checking If User Role Is Admin

I'm checking if the user is an admin

my code :

@if(auth()->user()->roles()->name == 'admin')
//blaa
@endif

But i get this error :

Undefined property: Illuminate\Database\Eloquent\Relations\BelongsToMany::$name s

how do i check if the user role is admin?

HELP

11 Oct
11 months ago

AO-IO left a reply on Protect User Settings From Being Access By Other Users

@Norbertho I tried this as well but no luck :\ anyways thank you

AO-IO left a reply on Protect User Settings From Being Access By Other Users

@D9705996 Well I fixed it by using the route in web.php

I guess I will stick to web.php for now.

AO-IO left a reply on Protect User Settings From Being Access By Other Users

this is the request error 401 :

http://prntscr.com/l51ewq

request headers :

http://prntscr.com/l51f6j

Response :

http://prntscr.com/l51fdr

the slug is being passed without problems but it keeps saying not auth! (the token is passed tho)

AO-IO left a reply on Protect User Settings From Being Access By Other Users

@D970 now I get 405 error .. I was getting 401

http://prntscr.com/l50e83 http://prntscr.com/l50eel

"Where you put this route web.php or api.php?"

yes in api.php

axios.put(`/api/profile/${this.data})

AO-IO left a reply on Protect User Settings From Being Access By Other Users

@D9705996 I'm using the default laravel auth

these two methods from PrivateProfileController


public function show($id)
  {
       $user = User::findBySlugOrFail($id);
     
       return response()->json($user);
  }

public function update(Request $request, $id)
  {
      $user = User::findBySlug($id);
      $user->update([
          'email'=>$request->email,
          'education_level'=>$request->education_level,
          'field'=>$request->field,
          
      ]);


      if($request->has('password')){
          $user->save([
              'password'=>$request->password
          ]);
      }

      return response()->json('user updated',200);

     
  
  }

AO-IO left a reply on Protect User Settings From Being Access By Other Users

@Norbertho I tried both id and slug not working And yes I'm sending the csrf-token

<profile-section1 data="{{$user->slug}}" ></profile-section1>

still getting this response :

message: "Unauthenticated."