simangae

simangae

Member Since 1 Year Ago

Experience Points
420
Total
Experience

4,580 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
0
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
420 XP
09 Oct
11 months ago

simangae left a reply on Return Data From Database With Vue

@petritr, @D9705996 Seems to work I think Chrome was caching, I had to clear all history and clean cache.. Thank You..

simangae left a reply on Return Data From Database With Vue

@petritr Yes bio shows with content

simangae left a reply on Return Data From Database With Vue

@D9705996 Still giving the same error, I have even changed the browser

simangae left a reply on Return Data From Database With Vue

@petritr Yes There Profiles shows as an object

simangae left a reply on Return Data From Database With Vue

@petritr It's in the front end

[Vue warn]: Error in render: "TypeError: Cannot read property 'bio' of null"

simangae left a reply on Return Data From Database With Vue

@petritr It's working fine since i commented out user.profile.bio but gives an error if uncomment it

  <div class="container-fluid">
     <div class="block-header">
            <h2>All Users</h2>
            <small class="text-muted">All Registered Users</small>
      </div>
            <hr>
            <button type="button" class="btn btn-raised btn-info waves-effect"  data-toggle="modal" data-target="#exampleModal"> <i class="material-icons">person_add</i> </button>
            <table class="table table-hover">
                <tbody>
                   <tr>
                       <th></th>
                       <th>Name</th>
                       <th>Email</th>
                       <th>Phone</th>
                       <th>Type</th>
                       <th>Modify</th>
                   </tr>
                   <tr v-for="user in users" :key="user.id">
                       <td></td>
                      <td>{{ user.name }}</td>
                       <td>{{ user.email }}</td>
                       <td>{{ user.id_number}}</td>
                       <td>{{ user.photo }}</td>
                       <!-- <td>{{ user.profile.bio}}</td> -->

                       <td>
                           <a href="">
                                <i class="material-icons">mode_edit</i>
                           </a>
                           <a href="">
                                <i class="material-icons">delete</i>
                           </a>
                       </td>

                   </tr>
                </tbody>
            </table>
       <Modal></Modal>
  </div>
</template>

<script>
import Modal from './Modal.vue';

    export default {
       components:{Modal},
       data(){
           return {
               users: [],
           }
       },
       methods: {
           loadStudent(){

                axios.get('/api/user').then(({ data }) => { this.users= data;})
                .catch((err) => console.error(err));


           },

       },
        created(){
            this.loadStudent();

        },

        }
</script>

simangae left a reply on Return Data From Database With Vue

@petritr it's the error in the editor.. with and red underline

simangae left a reply on Return Data From Database With Vue

@petritr Gives an error expected to have v-bind:key

simangae left a reply on Return Data From Database With Vue

@D9705996

[{"id":13,"name":"Joseph WhatNot","email":"[email protected]","email_verified_at":null,"phone":"0834602415","type":"admin","photo":"user.png","created_at":"2018-10-03 06:44:50","updated_at":"2018-10-03 06:44:50","profile":{"id":2,"user_id":13,"phone":null,"dob":"21 feb 2000","id_number":"93444245556","gender":"male","course":"MCA","address":"2nd Street\nHillside","bio":"Some info here","created_at":"2018-10-03 06:44:50","updated_at":"2018-10-03 06:44:50"}}]

simangae left a reply on Return Data From Database With Vue

@petritr return response()->json(User::all()->with('profile')->get());

Returns "Method Illuminate\Database\Eloquent\Collection::with does not exist.",…}

But when I change it to return response()->json(User::with('profile')->get());

it's working but I stilll can't access profile props

simangae left a reply on Return Data From Database With Vue

@D9705996

The output in the console

created_at: "2018-10-03 06:44:50"
email: "[email protected]"
email_verified_at: (...)
id: 13
name: "Joseph WhatNot"
phone: "0834602415"
photo: "user.png"
   profile: Object
   address: "2nd Street↵Hillside"
   bio: "Some info here"
   course: (...)
    created_at: "2018-10-03 06:44:50"
    dob: "21 feb 2000"
    gender: "male"
    id: 2
    id_number: "93444245556"
    phone: null
    updated_at: "2018-10-03 06:44:50"
    user_id: 13

simangae left a reply on Return Data From Database With Vue

@marty12321 I'm still getting the same error.. User::all() does not return the profile $users = User::with('profile')->latest()->get();

my controller

        return response()->json($users, 200);


 axios.get("api/user").then(response =>{this.users = response.data
              }).catch(error => console.log(error.response));


Table

 <tr v-for="user in users" :key="user.id">
                       <td></td>
                      <td>{{ user.name }}</td>
                       <td>{{ user.email }}</td>
                       <td>{{ user.phone }}</td>
                       <td>{{ user.photo }}</td>
                       <td>{{ user.profile.bio}}</td>

                       <td>
                           <a href="">
                                <i class="material-icons">mode_edit</i>
                           </a>
                           <a href="">
                                <i class="material-icons">delete</i>
                           </a>
                       </td>

                   </tr>```

simangae left a reply on Return Data From Database With Vue

@petritr I'm still leaning vuejs I'm not sure How can I access it

simangae left a reply on Return Data From Database With Vue

Its Actually array like this

[{id: 13, name:"Joseph WhatNot"......}

profile{ address: address: "2nd Street", bio:"Some info here" user_id: 13}

]

simangae left a reply on Return Data From Database With Vue

Yes There is a user_id foreign key.. If I access like this {{user.profile}} the profile object is showing with all it's properties however if I change it to {{user.profile.bio}} I get an error.

created_at: "2018-10-03 06:33:47"
email: "[email protected]"
email_verified_at: null
id: 11
name: "test 2"
phone: "0739764608"
photo: "user.png"
profile: {id: 1, user_id: 11, phone: null, dob: "21 July 1989", id_number: "928525554555", gender: "male",…}
type: "admin"
updated_at: "2018-10-03 06:33:47"



simangae started a new conversation Return Data From Database With Vue

Hi, I have two tables that has one to one relationship, when I try to access data from 2nd table, I get the "TypeError: Cannot read property 'bio' of null" .

Here my controller

return User::with('profile')->latest()->get();

RelationShip

public function profile(){ return $this->hasOne('App\StudentInfo'); }

Axios

axios.get("api/user").then(({ data }) => (this.users = data));

Table

{{ user.name }} {{ user.email }} {{ user.phone }} {{ user.photo }} {{ user.profile.bio}} //This gives me error when I remove It's working fine
                   <td>
                       <a href="">
                            <i class="material-icons">mode_edit</i>
                       </a>
                       <a href="">
                            <i class="material-icons">delete</i>
                       </a>
                   </td>

               </tr>
25 Jul
1 year ago

simangae left a reply on Update HasOne Relationship

Thank you so much!!,

23 Jul
1 year ago

simangae left a reply on Update HasOne Relationship

method="POST" Action="{{ route('students.update', $user->id)}}"

simangae left a reply on Update HasOne Relationship

Hi, It's Filled in..

class Student extends Model { protected $fillable = [ 'date_of_birth', 'id_number', 'gender', 'phone','address', ];

}

and the user model

protected $fillable = [ 'name', 'email', 'password','pro_pic', 'role','status', ];

and the Form

                      @csrf
                      @method('PUT')
                      
                    <fieldset>
                    <legend>Account Information</legend>
                    <div class="form-group">
                    <div class="picture-container">
                            <div class="picture">
                                <img src="/uploads/avatars/{{ $user->pro_pic }}" class="picture-src" id="wizardPicturePreview" title="">
                                <input name="pro_pic" id="wizard-picture" class="" type="file">
                            </div>
                             <h6 class="">Choose Picture</h6>
                    
                    </div>
                </div>
                <div class="container">
                    <div class="form-group col-md-5 ml-5">
                            
                        <div class="input-group">                         
                            <span class="input-group-text pt-4 "><i class="fa fa-user text-right"></i></span>
                            <input type="text" name="name" id="" class="form-control" value={{ $user->name }}>                           
                        </div>
                    </div>

                    <div class="form-group col-md-5 ml-5">
                        <div class="input-group">                         
                            <span class="input-group-text pt-4 "><i class="fa fa-envelope text-right"></i></span>
                            <input type="email" name="email" id="" class="form-control"  value={{ $user->email }}>                           
                        </div>
                    </div>

                    <div class="form-group col-md-5 ml-5">
                        <div class="input-group">                         
                            <span class="input-group-text pt-4 "><i class="fa fa-lock text-right"></i></span>
                            <input type="password" name="password" id="" class="form-control" placeholder="Password">                           
                        </div>
                    </div>

                    <div class="form-group col-md-5 ml-5">
                        <div class="input-group">                         
                            <span class="input-group-text pt-4 "><i class="fa fa-check text-right"></i></span>
                            <input type="password" name="confirm_password" id="" class="form-control" placeholder="Confirm Password">                           
                        </div>
                    </div>

                    <div class="form-group col-md-5 ml-5">
                        {{--  <label for="role">Select User Role</label>  --}}
                        
                            <select name="role"  class="form-control " data-style="btn-primary btn-outline">
                                
                                <option data-tokens="User" value="1">User</option>
                                <option  data-tokens="Admin" value="2">Admin</option>
                                <option data-tokens="user" value="3">Student</option>
                            </select>                           
                    </div>

                    <div class="form-group col-md-5 ml-5">
                            
                        <select name="status"  class="form-control " data-style="btn-primary btn-outline">
                                
                            <option data-tokens="User" value="1">Active</option>
                            <option  data-tokens="Admin" value="0">Disabled</option>
                        
                        </select> 
                                                          
                    </div>


                    </fieldset>
                    
                    <fieldset>
                        <legend>user Information</legend>
                        <div class="form-group col-md-5 ml-5">
                        <div class="input-group">
                            <span class="input-group-text pt-4 "><i class="fa fa-calendar text-right"></i></span>
                            <input type="text" name="date_of_birth" class="form-control mydatepicker"  value="{{ $user->student['date_of_birth'] }}">
                            
                        </div>
                        </div>

                        <div class="form-group col-md-5 ml-5">
                            <div class="input-group">                         
                                <span class="input-group-text pt-4 "><i class="fa fa-hashtag text-right"></i></span>
                                <input type="text" name="id_number" id="" class="form-control"  value="{{ $user->student['id_number'] }}">                           
                            </div>
                        </div>

                        <div class="form-group col-md-11 ml-5">
                                <div class="input-group">                         
                                    <span class="input-group-text pt-4 "><i class="fa fa-home text-right"></i></span>
                                    <textarea name="address" id="" class="form-control" placeholder="Address">{{ $user->student['address'] }}</textarea>                           
                                </div>
                            </div>

                        <div class="form-group col-md-5 ml-5">
                            <div class="input-group">                         
                                <span class="input-group-text pt-4 "><i class="fa fa-phone text-right"></i></span>
                                <input type="text" name="phone" id="" class="form-control"  value="{{ $user->student['phone'] }}">                           
                            </div>
                        </div>

                        <div class="form-group col-md-11 ml-5">
                                <div class="input-group">                         
                                    <span class="input-group-text pt-4 "><i class="fa fa-history text-right"></i></span>
                                    <textarea name="bio" id="" class="form-control" placeholder="Address">Bio</textarea>                           
                                </div>
                            </div>

                        
                        <div class="form-group col-md-11 ml-5">
                            <button class="btn btn-block btn-rounded" type="submit"><i class="fa fa-paper-plane"></i><span>Submit</span> </button>  
                        </div>

                        
                    </fieldset>
                </div>
                 
                   
                    
                </form>    

I also changed @method('PUT') to @method('PATCH').. Still didn't work..

the update method

public function edit($id) { $user = User::findOrFail($id); return view('students.edit', ['user' => $user]); }

public function update(Request $request, $id)
{
    $user = User::find($id);
    $user = new User;
    $user->name = $request->name;
    $user->email = $request->email;
    $user->password = Hash::make($request->password);
    $user->role = $request->role;
    $user->status = $request->status;

    if($request->hasFile('pro_pic')) {
        $image =  $request->file('pro_pic');
        $filename = time() . '.' .$image->getClientOriginalExtension();
        $location = public_path('uploads/avatars/' .$filename);
        Image::make($image)->resize(300, 300)->save($location);
        $user->pro_pic = $filename;
    }  
    $user->update();

    $profile = new Student;
        $profile->date_of_birth = $request->date_of_birth;
        $profile->id_number= $request->id_number;
       // $profile->gender = $request->gender;
        $profile->phone= $request->phone;
        $profile->address = $request->address;

    $user->student()->update($profile->toArray());
    return redirect()->route('students.index')->with('update', 'Student Has been updated!!');

}

Not really sure what I'm doing wrong

20 Jul
1 year ago

simangae left a reply on Update HasOne Relationship

Now No errors but it's not doing anything, It doesn't update

simangae left a reply on Update HasOne Relationship

Hi, Thanks But I tried that before and it produced this error

Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::update() must be of the type array, object given, called in..

Hence I tried to wrap it around array.

simangae started a new conversation Update HasOne Relationship

Need help, trying to update two tables that has one to one relationship, the store method is working fine but when i try to do update I'm getting the following error..

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update students set 0 =

My Store Method which is working fine

public function store(Request $request) { $user = new User; $user->name = $request->name; $user->email = $request->email; $user->password = Hash::make($request->password); $user->role = $request->role; $user->status = $request->status;

    if($request->hasFile('pro_pic')) {
        $image =  $request->file('pro_pic');
        $filename = time() . '.' .$image->getClientOriginalExtension();
        $location = public_path('uploads/avatars/' .$filename);
        Image::make($image)->resize(300, 300)->save($location);
        $user->pro_pic = $filename;
    }  
    $user->save();

    $profile = new Student;
        $profile->date_of_birth = $request->date_of_birth;
        $profile->id_number= $request->id_number;
       // $profile->gender = $request->gender;
        $profile->phone= $request->phone;
        $profile->address = $request->address;
    $user->student()->save($profile);
    return redirect()->back()->with('success', 'New Student was Added!!');
}

Then The update method which is producing the error.

public function edit($id) { $user = User::findOrFail($id); return view('students.edit', ['user' => $user]); }

public function update(Request $request, $id)
{
    $user = User::findOrFail($id);
    $user = new User;
    $user->name = $request->name;
    $user->email = $request->email;
    $user->password = Hash::make($request->password);
    $user->role = $request->role;
    $user->status = $request->status;

    if($request->hasFile('pro_pic')) {
        $image =  $request->file('pro_pic');
        $filename = time() . '.' .$image->getClientOriginalExtension();
        $location = public_path('uploads/avatars/' .$filename);
        Image::make($image)->resize(300, 300)->save($location);
        $user->pro_pic = $filename;
    }  
    $user->update();

    $profile = new Student;
        $profile->date_of_birth = $request->date_of_birth;
        $profile->id_number= $request->id_number;
       // $profile->gender = $request->gender;
        $profile->phone= $request->phone;
        $profile->address = $request->address;
    $user->student()->update(array($profile));
    return redirect()->route('students.index')->with('update', 'Student Has been updated!!');

}
03 May
1 year ago

simangae left a reply on Form Not Doing Anything

Thank You that solved the problem

simangae left a reply on Form Not Doing Anything

return true; on authorize();

simangae started a new conversation Form Not Doing Anything

Hi, I'm new in laravel I'm trying to post form data but form is not doing anything. Here are the routes-: Route::resource('admin/users', 'UserController');

UserController

public function store(UsersRequest $request) {

   User::create($request->all());
   return view('admin.users');


}

And the Form

@csrf
               <div class="form-group m-b-25">
                    <div class="col-12">
                    <label for="name">Name</label>
                    <div class="input-group-prepend">

                    <div class="input-group-prepend">
                    <span class="input-group-text" id="basic-addon1"><i class="fa fa-vcard-o  text-primary"></i></span>
                    </div>
                    
                    <input class="form-control" name="name" type="text" id="text" required="" placeholder="full Name">
                    </div>
                    </div>
                </div>

                <div class="form-group m-b-25">
                    <div class="col-12">
                    <label for="email">Email</label>
                    <div class="input-group-prepend">

                    <div class="input-group-prepend">
                    <span class="input-group-text" id="basic-addon1"><i class="fa fa-envelope text-primary"></i></span>
                    </div>
                    
                        <input class="form-control" name="email" type="email" id="email" required="" placeholder="[email protected]">
                    </div>
                    </div>
                </div>

                <div class="form-group m-b-25">
                    <div class="col-12">
                        <label for="role">Role</label>
                    <select class="selectpicker show-tick" data-style="btn-primary" name="role">
                        @foreach($roles as $role)
                        <option value = "{{$role->id}}">{{$role->name}}</option>
                        @endforeach
                    </select>
                    </div>
                </div>

                <div class="form-group m-b-25">
                    <div class="col-12">
                        <label for="status">Status</label>
                    <select class="selectpicker show-tick" data-style="btn-primary" name="status">
                        <option value = "1">Active</option>
                        <option value = "0">Disabled</option>

                    </select>
                    </div>
                </div>

                <div class="form-group m-b-25">
                    <div class="col-12">
                    <label for="avatar">Profile Pic</label>
                    <div class="input-group-prepend">

                    <div class="input-group-prepend">
                    <span class="input-group-text" id="basic-addon1"><i class="fa fa-file-image-o text-primary"></i></span>
                    </div>
                    
                     <input type="file" class="filestyle" name="avatar" data-btnClass="btn-primary">
                    </div>
                    </div>
                </div>

                    <div class="form-group m-b-25">
                    <div class="col-12">
                    <label for="password">Password</label>
                    <div class="input-group-prepend">

                    <div class="input-group-prepend">
                    <span class="input-group-text" id="basic-addon1"><i class="fa fa-lock text-primary"></i></span>
                    </div>
                    
                        <input class="form-control" name="password" type="password" id="password" required="" placeholder="&#183;&#183;&#183;&#183;&#183;">
                    </div>
                    </div>
                </div>

                
                <div class="form-group account-btn text-center m-t-10">
                    <div class="col-12">
                        <button class="btn w-lg btn-block btn-primary waves-effect waves-light" type="submit">
                        <i class="fa fa-user-plus m-r-5"></i> <span>ADD NEW USER</span>
                        </button>
                    </div>
                </div>

            </form>