AO-IO

AO-IO

Member Since 1 Month Ago

Experience Points 990
Experience
Level
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

06 Dec
3 days 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
5 days 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 registration? instead of redirecting to /email/verify page?

thanks

28 Nov
1 week 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 a good practice?

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
2 weeks 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 - @realrandyallen it was a problem with the browser cache thanks

18 Nov
3 weeks 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
3 weeks 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
1 month 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
1 month ago

AO-IO left a reply on Export To Excel

@tykus

``PHP 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 : 

```PHP

$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
1 month 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
1 month 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 courses(){
        return $this->belongsToMany('App\Course');
    }
}

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?

thanks

26 Oct
1 month ago

AO-IO left a reply on Attach Many Values Relations

@tykus I realized that I didn't make my 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
1 month 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 use 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
1 month 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
1 month ago

AO-IO left a reply on Checking If User Role Is Admin

Solved by using

auth()->user()->roles === 'admin'

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
1 month 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

@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."

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

@Norbertho well any auth user can access others settings :\

AO-IO started a new conversation Protect User Settings From Being Access By Other Users

Hello,

I made this middleware to protect "user settings " from being access by other auth users.

   public function handle($request, Closure $next)
    {
         if ($request->slug != auth()->user()->slug) {
            return redirect()->to('/');
        }
        return $next($request);
    }

And I'm using vueJs to update the profile

I managed to get the slug to pass it to my url :

Route::put('/profile/{slug}','[email protected]');
  axios.put(`/api/profile/${this.data}`)

I used props to get my slug.

so the problem is when I ever use this route it says 401 or 500 error in the console:.

am I doing this wrong?

how I can solve this problem so VUEJS can match the request URL with the auth user (Like in the middleware)?