Olamilekan

Olamilekan

Member Since 7 Months Ago

Experience Points
1,050
Total
Experience

3,950 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 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.

Level 1
1,050 XP
May
12
4 months ago
Activity icon

Replied to REST Api

@flightsimmer668 thank you very much for your time, I think i will go through the series, that will way i will get more exposure, I having a hard time understanding the code, I have been going through the docs all day, and it isn't really making much sense to me. so i will do as you have advised, go through the series, I am sure i will learn a lot from the series, I really appreciate, thank for the eye opener. God bless. Thank you once again

Activity icon

Replied to REST Api

@flightsimmer668 please, I am pretty new to API technology, Please i still don't understand how to implement this in a away i can display the data i am getting to my view.

Activity icon

Started a new Conversation REST Api

Please how can i consume RapidAPI ( https://rapidapi.com/ ) in laravel, the examples i have been seeing made use of docker, which looking quite complex to me please. how can conume their APIs without using docker

May
09
4 months ago
Activity icon

Replied to Hello Please How Can I Get A Specific Data From My Pivot Table

Thank you, will try this as well

Activity icon

Replied to Hello Please How Can I Get A Specific Data From My Pivot Table

Thank you will try this out right away

May
07
4 months ago
Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'from_date' Doesn't Have A Default Value

Thank you, I actually solved this yesterday... Thank you very much....

I do have another issue i am currently battling, please can you help sir

Activity icon

Started a new Conversation Hello Please How Can I Get A Specific Data From My Pivot Table

I have models user and leave, a user can have many leaves and a leave can belong to many users, below is my model.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Leave extends Model
{
    //
    protected $fillable = ['leave_type'];
    public function users()
    {
        return $this->belongsToMany('App\User');
    }
}
namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function leaves()
    {
        return $this->belongsToMany(Leave::class)->withPivot('leave_type','from_date', 'to_date', 						'description','status')->withTimestamps();
    }

}

Below is my code, which returns all the leaves related to the use, But I want just a one of the leaves by passing the ID of the leave, after clicking on a button in my view

    public function approveLeave($id)
    {
        $data = User::with('leaves')
        ->select('id', 'employee_name')
        ->find($id);
         return json_encode($data);
        // return view('adminpages.editEmployeeProfile')->with(['user' => $user]);
    }

May
06
4 months ago
Activity icon

Started a new Conversation SQLSTATE[HY000]: General Error: 1364 Field 'from_date' Doesn't Have A Default Value

Please I am trying to store some data into my pivot table.

Below is my Leave Classs

class Leave extends Model
{
    //
    protected $fillable = ['leave_type','leave_id', 'from_date', 'to_date', 'description','status'];
    public function user()
    {
        return $this->belongsToMany('App\User');
    }
}

Below is my User Class

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    public function leaves()
    {
        return $this->belongsToMany(Leave::class)->withPivot('from_date', 'to_date', 'description','status')->withTimestamps();
    }

}


public function storeleave(Request $request)
    {

        $this->validate($request, [
            'leave_type' => 'required',
            'from_date' => 'required',
            'to_date' => 'required',
            'description' => 'required',

        ]);

        $todaysDate = date('Y-m-d');



        $from_date = $request->input('from_date');

        $to_date = $request->input('to_date');

        // ("Todays date. $todaysDate);


        if ($todaysDate < $from_date) {

            if ($to_date <= $from_date) {
                return redirect('/apply/for/leave')->with('error', 'From Date: ' . $from_date . ' must be greater than To Date: ' . $to_date . '. Please choose a date greater than From Date');
            } else {

                $user = User::find(Auth::id());

                $sync_leave_data =  [
                    'user_id' => Auth::id(),
                    'leave_id' => $request->input('leave_type'),
                    'from_date' => $request->input('from_date'),
                    'to_date' => $request->input('to_date'),
                    'description' => $request->input('description'),

                ];

                // dd($sync_leave_data);
                $user->leaves()->attach($sync_leave_data);
                return redirect('/apply/for/leave')->with('success', 'Leave form has been submitted');
            }
        } else {
            return redirect('/apply/for/leave')->with('error', 'From Date: ' . $from_date . ' Can not be less than or equal to Today\'s Date: ' . $todaysDate . '. Please choose a date greater than today\'s date');
        }
    }

If dd($syn_leave_data) i see all my outputs

Apr
30
4 months ago
Activity icon

Started a new Conversation How To Pass Multiple Data To Json Response

How can i pass the deduction and allowance model to my ajax

 public function fetchEmployeeFinance($id)
    {

        if (request()->ajax()) {
            if ($id) {
                $deductions = Deduction::all();
                $allowances = Allowance::all();
                $data = User::with('account','allowances.users', 'deductions.users')
                    ->select('id', 'employee_name', 'email','department_id', 'designation_id', 'phone_number')
                    ->where('id', $id)
                    ->get();
            }
            return json_encode(['result'=>$data]);
        }

    }
Apr
26
4 months ago
Activity icon

Replied to How Do I Store A Multiple Json Object Into Database

Okay, I checked and did a little update to my code

  public function storeAttendance(Request $request)
    {
        $input_data = $request->all();
        if (request()->ajax()) {
            
            foreach ($input_data as $row ) {
                Attendance::create([
                    'user_id'           =>  $row["id"],
                    'department_id'     =>  $row["department_id"],
                    'attendance_date'   =>  $row["attendance_date"],
                    'attendance_status' =>  $row["attendance_status"],
    
                ]);
            }
        }
    }

I am getting the error "local.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null "

but if I do this

  public function storeAttendance(Request $request)
    {
        $input_data = $request->all();
        
        return $input_data;
    }

I get this in my console from this js


        attendance_data.forEach(function(payload){
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: 'post',
                url: "/store/attendance",
                dataType: 'json',           
                data:  JSON.stringify(payload),
                success: function(payload) {
                    console.log(payload);
                },
                error: function() {
                    console.log("Error");
                }
            });
        });
{{"attendance_date":"2020-04-26","attendance_status":"false","id":"1","employee_name":"Admin","department_id":"2","department":{"id":"2","department_name":"Material_Recording_Clerks","created_at":null,"updated_at":null}}: null}


{{"attendance_date":"2020-04-26","attendance_status":"false","id":"2","employee_name":"User","department_id":"1","department":{"id":"1","department_name":"Information_Clerks","created_at":null,"updated_at":null}}: null}



 {{"attendance_date":"2020-04-26","attendance_status":"false","id":"3","employee_name":"Chinyere_Lynda","department_id":"1","department":{"id":"1","department_name":"Information_Clerks","created_at":null,"updated_at":null}}: null}
Apr
25
5 months ago
Activity icon

Started a new Conversation How Do I Store A Multiple Json Object Into Database

Below is my code

$("#mark_attendance").on("click", function(event) {
        event.preventDefault();
        var table = $("#attendance_table").DataTable();
        let attendance_status = [];
        $("select[name='attendance_status[]']").each(function() {
            attendance_status.push($(this).val());
        });

        let attendance_date = [];
        $("input[name='attendance_date[]']").each(function() {
            attendance_date.push($(this).val());
        });

        var data = table
            .rows()
            .data()
            .toArray();
        
         data = data.map((item,i)=>{
            return {
                attendance_status: attendance_status[i],...item,
            }
        })

       var  attendance_data = data.map((item,i)=>{
            return {
                attendance_date: attendance_date[i],...item
            }
        })
      
    
        attendance_data.forEach(function(payload){
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: 'post',
                url: "/store/attendance",
                dataType: 'json',           
                data: payload,
                success: function(payload) {
                    console.log(payload);
                },
                error: function() {
                    console.log("Error");
                }
            });
        });
        
       
    });

Below is my controller method

    public function storeAttendance(Request $request)
    {
        $input_data = $request->all();
        if (request()->ajax()) {
            
            foreach ($input_data["data"] as $row) {
                Attendance::create([
                    'user_id'           =>  $row["id"],
                    'department_id'     =>  $row["department_id"],
                    'attendance_date'   =>  $row["attendance_date"],
                    'attendance_status' =>  $row["attendance_status"],
    
                ]);
            }
        }
     return ($input_data);
       
    }

I am getting POST http://127.0.0.1:8000/store/attendance 500 (Internal Server Error)

Activity icon

Started a new Conversation Please How Do I Save This Data Into My Database

Please after clicking this button

    $("#mark_attendance").on("click", function(event) {
        event.preventDefault();
        var table = $("#attendance_table").DataTable();
        let attendance_status = [];
        $("select[name='attendance_status[]']").each(function() {
            attendance_status.push($(this).val());
        });

        let attendance_date = [];
        $("input[name='attendance_date[]']").each(function() {
            attendance_date.push($(this).val());
        });

        var data = table
            .rows()
            .data()
            .toArray();
        
         data = data.map((item,i)=>{
            return {
                attendance_status: attendance_status[i],...item,
            }
        })

       var  attendance_data = data.map((item,i)=>{
            return {
                attendance_date: attendance_date[i],...item
            }
        })
      

        attendance_data.forEach(function(payload){
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: 'post',
                url: "/store/attendance",
                dataType: 'json',           
                data: payload,
                success: function(payload) {
                    console.log(payload);
                },
                error: function() {
                    console.log("Error");
                }
            });
        });
        
       
    });

I get the below value


{attendance_date: "2020-04-25"
attendance_status: "false"
id: "1"
employee_name: "Admin"
department_id: "2"
department: {id: "2", department_name: "Material Recording Clerks", created_at: null, updated_at: null}
},

{attendance_date: "2020-04-25"
attendance_status: "false"
id: "2"
employee_name: "User"
department_id: "1"
department: {id: "1", department_name: "Information Clerks", created_at: null, updated_at: null}
},

{attendance_date: "2020-04-25"
attendance_status: "false"
id: "3"
employee_name: "Chinyere Lynda"
department_id: "1"
department: {id: "1", department_name: "Information Clerks", created_at: null, updated_at: null}
}

Below is my controller

 public function storeAttendance(Request $request)
    {
        return response()->json($request->all());
    }

Please how can i save the id, attendance_date, attendance_status and departement_id in my database?

I am trying to save the above data in to this columns

user_id	|department_name|	attendance_date	| attendance_status
Apr
01
5 months ago
Activity icon

Started a new Conversation Load Many To Many Intermediate Table Data Through Edit Function

Please I am trying to edit user details. I am unable to get the datas in the pivot table.

I have allowance_user and deduction_user table that contains the data i need.

I am getting the "Call to undefined relationship [allowance] on model [App\User]." error .

I have defined the following relationships

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    //Defining 
    public function account()
    {
        return $this->hasOne('App\Account');
    }

    public function department()
    {
        return $this->belongsTo('App\Department');
    }

    public function designation()
    {
        return $this->belongsTo('App\Designation');
    }



    // Defining Many to Many Relationship 

    public function allowances()
    {
        return $this->belongsToMany(Allowance::class)->withPivot('allowance_name','allowance_value')->withTimestamps();
    }

    
    public function deductions()
    {
        return $this->belongsToMany(Deduction::class)->withPivot('deduction_name','deduction_value')->withTimestamps();
    }

}


class Deduction extends Model
{
    protected $fillable = [
        'deduction_name'
    ];


    public function users()
    {
        return $this->belongsToMany(User::class);
    }

}


class Allowance extends Model
{
    protected $fillable = [
        'allowance_name'
    ];

    public function users()
    {
        return $this->belongsToMany(User::class);
    }
}

Below is my code

 public function edit($id)
    {
        $user = User::with('account','department','designation', 'allowance')->find($id);
       

        dd($user);
     
    }
Mar
30
5 months ago
Activity icon

Replied to Populating Many To Many Intermediate Table With Array Input

Oh, I get this, I am not trying to update the table, I am inserting data into the table and i have tried this.

I still got this error

SQLSTATE[HY000]: General error: 1364 Field 'deduction_name' doesn't have a default value (SQL: insert into `deduction_user` (`created_at`, `deduction_id`, `updated_at`, `user_id`) values (2020-03-30 21:42:15, 6, 2020-03-30 21:42:15, 6))

I noticed the user id is been assigned to deduction id as well.

Then my deduction name and value input are been generated dynamically i.e a user can have more than one deductions

NOTE: my deductions are been loaded to the user interface from the database and each has an ID. I can access see the id on the user interface, but i have not been able to access in my store function



        $deduction = Deduction::all();

        

        $user->deductions()->attach($user->id);

        $user->deductions()->attach($deduction->id, [
            'deduction_name' => $request->input('deduction_name'),
            'deduction_value'=> $request->input('deduction_value')
        ]);



Activity icon

Started a new Conversation Populating Many To Many Intermediate Table With Array Input

Please I am trying to insert multiple deduction name and it corresponding values into my database .

the intermediate table has the following coloumn user_id, deduction_id, deduction_name, deduction_value

The deduction name and value inputs are been dynamically generated using JQuery.

I get the below error ... I am unable to get the deductions id and get the deduction_name and deduction_value data

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1364 Field 'deduction_name' doesn't have a default value (SQL: insert into `deduction_user` (`created_at`, `deduction_id`, `updated_at`, `user_id`) values (2020-03-30 19:18:22, 5, 2020-03-30 19:18:22, 5))


  public function store(Request $request)
    {

   

        //Creating User model Instance 
        $user = new User();


        // accepting User model datas
        $user->employee_name = $request->input('employee_name');
        $user->email = $request->input('email');
        $password = Hash::make($request->input('password'));
        $user->password = $password;
        $user->date_of_birth = $request->input('date_of_birth');
        $user->gender = $request->input('gender');
        $user->phone_number = $request->input('phone_number');
        $user->nationality = $request->input('nationality');
        $user->address = $request->input('address');
        $user->marital_status = $request->input('marital_status');
        $user->department_name = $request->input('department_name');
        $user->designation_name = $request->input('designation_name');
        $user->resumption_date = $request->input('resumption_date');
        $user->employee_status = $request->input('employee_status');


        //Checking if file upload is present 

        if ($request->hasFile('user_photo')) {
            // Get file name with extension
            $fileNameWithExtension = $request->file('user_photo')->getClientOriginalName();

            //Get file name only
            $fileName = pathinfo($fileNameWithExtension, PATHINFO_FILENAME);

            //Get file extension
            $fileExtension = $request->file('user_photo')->getClientOriginalExtension();

            $fileNameToStore = $fileName . '_' . time() . '.' . $fileExtension;

            //Upload image

            $imagePath = $request->file('user_photo')->storeAs('public/Employee_Images', $fileNameToStore);
        }



        //Saving User model Instance 

        $user->save();


        $deduction = Deduction::all();

        

        $user->deductions()->attach($user->id);


        $user->deductions()->attach($request->input('deduction_name'));
        $user->deductions()->attach($request->input('deduction_value'));

        $user->deductions()->attach($deduction->id);



       


    }

Mar
28
5 months ago
Activity icon

Replied to Inserting Multiple Array Into Database In Laravel

I am not getting errors,


'allowance_id'=>$request->id, //(this should be getting the allowance id)
'user_id'=>$request->id,

is an error. but that is not the issue.

I am trying to save multiple allowance and deductions that relates to a particular employee.

allowance and deduction types are already saved in the database with an id.

An employee can have multiple allowance and deduction.

the AllowanceUser and DeductionUser Model is where i want the allowances and deductions corresponding to each user be stores

the allowance_user table has the following column

 Schema::create('allowance_user', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->unsignedBigInteger('allowance_id');
        $table->unsignedBigInteger('user_id');
        $table->string('allowance_name');
        $table->integer('allowance_value');
        $table->timestamps();
    });
Activity icon

Started a new Conversation Inserting Multiple Array Into Database In Laravel

Hello Good day everyone, Please i am trying to insert into my database multiple allowance and deduction when creating a new employee in my project.

Datas passed through to The AllowanceUser and DeductionUser model are not been saved. But user and account model datas are saved

Using dd($input) the datas passed through are shown for all model

Below is my current code

         //Creating User model Instance 
        $user = new User();


        // accepting User model datas
        $user->employee_name = $request->input('employee_name');
        $user->email = $request->input('email');
        $password = Hash::make($request->input('password'));
        $user->password = $password;
        $user->date_of_birth = $request->input('date_of_birth');
        $user->gender = $request->input('gender');
        $user->phone_number = $request->input('phone_number');
        $user->nationality = $request->input('nationality');
        $user->address = $request->input('address');
        $user->marital_status = $request->input('marital_status');
        $user->department_name = $request->input('department_name');
        $user->designation_name = $request->input('designation_name');
        $user->resumption_date = $request->input('resumption_date');
        $user->employee_status = $request->input('employee_status');


        //Checking if file upload is present 

        if ($request->hasFile('user_photo')) {
            // Get file name with extension
            $fileNameWithExtension = $request->file('user_photo')->getClientOriginalName();

            //Get file name only
            $fileName = pathinfo($fileNameWithExtension, PATHINFO_FILENAME);

            //Get file extension
            $fileExtension = $request->file('user_photo')->getClientOriginalExtension();

            $fileNameToStore = $fileName . '_' . time() . '.' . $fileExtension;

            //Upload image

            $imagePath = $request->file('user_photo')->storeAs('public/Employee_Images', $fileNameToStore);
        }

     
        
        //Saving User model Instance 
        
        $user->save();

    //getting all input using request all

        $input = $request->all();

        for ($i = 0; $i <= count($input['deduction_name']); $i++) {

            if (empty($input['deduction_name'][$i]) || !is_numeric($input['deduction_name'][$i])) continue;

            $data = [
                'allowance_id'=>$request->id,
                'user_id'=>$request->id,
                'deduction_value' => $input['deduction_value'][$i],
                'deduction_name' => $input['deduction_name'][$i]
            ];

            DeductionUser::create($data);
        }
        

        for ($i = 0; $i <= count($input['allowance_name']); $i++) {

            if (empty($input['allowance_name'][$i]) || !is_numeric($input['allowance_name'][$i])) continue;

            $data = [
                'allowance_value' => $input['allowance_value'][$i],
                'allowance_name' => $input['allowance_name'][$i]
            ];

            AllowanceUser::create($data);
        }
$account = new Account();
        $account->user_id = $request->id;
        $account->basic_salary = $request->input('basic_salary');
        $account->total_salary = $request->input('total_salary');
        $account->account_name = $request->input('account_name');
        $account->account_number = $request->input('account_number');
        $account->bank_name = $request->input('bank_name');
        $account->save();