php – Laravel project doesn't load some support packages after cloning from github to localhost server-ThrowExceptions

Exception or error:

I created a laravel project in xammp/localhost and I push it to my github repository.Then I had to delete my local copy and reinstall xammp due to mysql db error.So I clone my repository back to xammp/htdocs through command line.
then i ran

“composer install”

“composer update”

“npm install”

“npm run dev”

“php artisan storage:link”

commands.

But now it seems some of support packages doesn’t load correctly.

These are the errors I get,

Illuminate\Database\QueryException
SQLSTATE[01000]: Warning: 1265 Data truncated for column ‘document_id’ at row 1 (SQL: insert into leave_requests (approved_by, category, created_at, document_id, end, reason, request_by, start, status, type) values (?, full day, 2020-03-17 10:32:29, 9a863c30-683a-11ea-aa56-115572db8558.jpg, 2020-03-19, sdfgh, 2, 2020-03-15, pending, no pay))

and

Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘approved_by’ cannot be null (SQL: insert into expense_claim (amount, approved_by, bill_id, created_at, date, reason, request_by, status) values (54.20, ?, 6dc45780-683a-11ea-a136-c3ad164f7663.jpg, 2020-03-17 10:31:14, 2020-03-15, sdfgh, 2, pending))

These are related to two forms which store values in mysql db,and they worked just fine before reinstall.
Here is the code for those forms,

<?php

    namespace App\Http\Controllers;
    
    use App\User;
    use App\Http\Controllers\Controller;
    use Illuminate\Support\Facades\DB;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Hash;
    use Illuminate\Support\Str;
    use Illuminate\Http\UploadedFile;
    use Illuminate\Support\Facades\Storage;
    use Uuid;
    
    class ExpenseClaimRequestController extends Controller
{
        /**
         * Show the application dashboard.
         *
         * @return \Illuminate\View\View
         */
        public function index()
        {
            $id = auth()->id();
            $expense_claim_requests = DB::table('expense_claim')->where('request_by', '=', $id)->get();  
            $to_approve = DB::table('expense_claim')->where('approved_by', '=', $id)->get();
      
            return view('expense_claim.view',  compact('expense_claim_requests','to_approve'));
          
           
        }
        public static function get_user_name($user_id)
        {
            $user_=DB::table('users')->select('name')->where([['id', '=', $user_id],])->first();
            
            return $user_;
        }
    
        public static function reject(Request $request)
        {
            $claimid=$request->requestId;
            DB::table('expense_claim')->where('claim_id', '=',  $claimid)->update(['status' =>'rejected']); 
    
            return redirect()->to('/expenseClaim'); 
          
            
        }
        public static function approve(Request $request)
        {
            $claimid=$request->requestId;
            DB::table('expense_claim')->where('claim_id', '=',  $claimid)->update(['status' => 'approved']);
    
            return redirect()->to('/expenseClaim');    
        }
    
        /**
         * Store new events.
         *
         * @return \Illuminate\View\View
         * @param  \App\Http\Request   $request
         */
        public function store(Request $request)
        {
            $id = auth()->id();
            $doc = $request->file('bill');
            $manager_supervisor = DB::table('users')->where('id', '=', $id)->first();
            if($doc!=null){
                $uuid = Uuid::generate()->string;
                $bill_doc_name = $uuid.'.'.$doc->getClientOriginalExtension();
                $folder = '/uploads/expense_claim/';
                $filePath = $folder . $bill_doc_name;
                $this->uploadOne($doc, $folder, 'public', $bill_doc_name);
            }else{
                $bill_doc_name =null;
            } 
            if($request->claim_id_=="add"){

                DB::table('expense_claim')->insert([
                    [

                        'bill_id'=>$bill_doc_name,
                        'reason' => $request->reason,
                        'date'=>$request->date_,
                        'amount'=>$request->amount,
                        'request_by'=>$id,
                        'approved_by'=>$manager_supervisor->supervisor_manager,
                        'status'=>"pending",
                        'created_at'=>now(),

                    ],
                    ]);
            }else{

                DB::table('expense_claim')->where('claim_id', '=', $request->claim_id_)->update(
                    array(

                        'bill_id'=>$bill_doc_name,
                        'reason' => $request->reason,
                        'date'=>$request->date_,
                        'amount'=>$request->amount,
                        'request_by'=>$id,
                        'approved_by'=>$manager_supervisor->supervisor_manager,
                        'status'=>"pending",
                        'updated_at'=>now(),

                        )
                    );

            }
        return redirect()->route('expenseClaim')->withStatus(__('Leave request successfully updated.'));
           
        }
        public static function destroy(Request $request)
        {
            $claimid=$request->requestId;
            DB::table('expense_claim')->where('claim_id', '=',  $claimid)->delete();
            return redirect()->to('/expenseClaim'); 
        }
        
    
        public function index2(Request $request)
        {
            
            $claimid=$request->requestId;

            if($claimid=="add"){
                $claim_req =null;
            }else{
                $claim_req = DB::table('expense_claim')->where('claim_id', '=', $claimid)->first(); 
            } 
            return view('expense_claim.add_edit',compact('claimid','claim_req'));
        }
    
         public function uploadOne(UploadedFile $uploadedFile, $folder = null, $disk = 'public', $filename = null)
        {
            $name = !is_null($filename) ? $filename : Str::random(25);
    
            $path =storage_path('uploads/expense_claim/'.$filename.'');
    
            if( Storage::exists($path)){
              
             Storage::disk('public')->delete('uploads/expense_claim/'.$filename.'');  
            }
            $file = $uploadedFile->storeAs($folder, $name, $disk);
          
            return $file;
        } 
    
          /**
         * Store new events.
         *
         * @return \Illuminate\View\View
         * 
         */
        public function download_file($file_name)
        {
            return response()->download(storage_path("app/public/uploads/expense_claim/{$file_name}"));
        }
    
    }
    
@extends('layouts.app')

@section('content')
    @include('layouts.headers.cards')
    
    <div class="container-fluid mt--7">
        <div class="row">
            <div class="col-xl-12 mb-5 mb-xl-0">
                <div class="card bg-white shadow">
                    <div class="card-body">
                    <form id="addEventForm" method="post" enctype="multipart/form-data" action="{{ route('expenseClaim.store') }}" autocomplete="off">
                            @csrf
                        <div class="pl-lg-4">
                            <input type="text" name="claim_id_" id="input-claim_id" hidden>
                            <div class="form-group{{ $errors->has('bill') ? ' has-danger' : '' }}">
                                <label class="form-control-label" for="input-bill">{{ __('Receipt/Bill') }}</label>
                                <input type="file" name="bill" id="input-bill" class="form-control form-control-alternative{{ $errors->has('bill') ? ' is-invalid' : '' }}" >
                            </div>
                            <div class="form-group{{ $errors->has('reason') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-reason">{{ __('Reason') }}</label>
                                    <input type="text" name="reason" id="input-reason" class="form-control form-control-alternative{{ $errors->has('reason') ? ' is-invalid' : '' }}" placeholder="{{ __('Reason') }}"  required autofocus>

                                    @if ($errors->has('reason'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('reason') }}</strong>
                                        </span>
                                    @endif
                            </div>
                            <div class="form-group{{ $errors->has('date_') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-date_">{{ __('Date') }}</label>
                                    <input type="date" name="date_" id="input-date_" class="form-control form-control-alternative{{ $errors->has('date_') ? ' is-invalid' : '' }}" placeholder="{{ __('Date') }}" autofocus>

                                    @if ($errors->has('date_'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('date_') }}</strong>
                                        </span>
                                    @endif
                            </div>
                            <div class="form-group{{ $errors->has('amount') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-amount">{{ __('Bill Amount') }}</label>
                                    <input type="number" step=".01" min="0" name="amount" id="input-amount" class="form-control form-control-alternative{{ $errors->has('amount') ? ' is-invalid' : '' }}" placeholder="{{ __('Bill amount') }}" autofocus>

                                    @if ($errors->has('amount'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('amount') }}</strong>
                                        </span>
                                    @endif
                            </div>



                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary mt-4">{{ __('Save') }}</button>
                            </div>       
                        </div>
                    </form>
                </div> 
                    </div>
                </div>
            </div>
        </div>
<script>


document.addEventListener('DOMContentLoaded', function() {

    var claim_id = @json($claimid);
    var val = @json('add');
    
    var values=@json($claim_req);


 $("#input-claim_id").val(claim_id);        
      
});

</script>
        @include('layouts.footers.auth')
    </div>
@endsection

@push('js')

    <script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.min.js"></script>
    <script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.extension.js"></script>

@endpush

and second form,

@extends('layouts.app')

@section('content')
    @include('layouts.headers.cards')
    
    <div class="container-fluid mt--7">
        <div class="row">
            <div class="col-xl-12 mb-5 mb-xl-0">
                <div class="card bg-white shadow">
                    <div class="card-body">

      <form id="addEventForm" method="post" enctype="multipart/form-data" action="{{ route('leave.store') }}" autocomplete="off">
                            @csrf
                            <div class="pl-lg-4">
                            <input type="text" name="leave_id_" id="input-leave_id" hidden>

                            <div class="form-group{{ $errors->has('leave_document') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-leave_document">{{ __('Document') }}</label>
                                    <input type="file" name="leave_document" id="input-leave_document" class="form-control form-control-alternative{{ $errors->has('leave_document') ? ' is-invalid' : '' }}" >
                                </div>
                                <div class="form-group{{ $errors->has('reason') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-reason">{{ __('Reason') }}</label>
                                    <input type="text" name="reason" id="input-reason" class="form-control form-control-alternative{{ $errors->has('reason') ? ' is-invalid' : '' }}" placeholder="{{ __('Reason') }}" required autofocus>

                                    @if ($errors->has('reason'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('reason') }}</strong>
                                        </span>
                                    @endif
                                </div>
                
                                <div class="form-group{{ $errors->has('start') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-start">{{ __('Start date') }}</label>
                                    <input type="date" name="start" id="input-start" class="form-control form-control-alternative{{ $errors->has('start') ? ' is-invalid' : '' }}" placeholder="{{ __('Start date') }}" autofocus>

                                    @if ($errors->has('start'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('start') }}</strong>
                                        </span>
                                    @endif
                                </div>
                                <div class="form-group{{ $errors->has('end') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-end">{{ __('End date') }}</label>
                                    <input type="date" name="end" id="input-end" class="form-control form-control-alternative{{ $errors->has('end') ? ' is-invalid' : '' }}" placeholder="{{ __('End date') }}"  autofocus>

                                    @if ($errors->has('end'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('end') }}</strong>
                                        </span>
                                    @endif
                                </div>
                                <div class="form-group{{ $errors->has('category') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-category">{{ __('Category') }}</label>
                                    
                                    <select name="category" id="input-category" class="form-control form-control-alternative{{ $errors->has('category') ? ' is-invalid' : '' }}" placeholder="{{ __('Category') }}"   autofocus>
  
                                    <option value="full day">Full day</option>
                                    <option value="half day">Half day</option>
                                    <option value="short leave">Short leave</option>
           
                                    </select>
                                    
                                    @if ($errors->has('category'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('category') }}</strong>
                                        </span>
                                    @endif
                                </div>
                                <div class="form-group{{ $errors->has('type') ? ' has-danger' : '' }}">
                                    <label class="form-control-label" for="input-type">{{ __('Type') }}</label>
                                    
                                    <select name="type" id="input-type" class="form-control form-control-alternative{{ $errors->has('type') ? ' is-invalid' : '' }}" placeholder="{{ __('Type') }}"   autofocus>
  
                                    <option value="no pay">No pay</option>
                                    <option value="casual">Casual</option>
                 
                                    </select>
                                    
                                    @if ($errors->has('type'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('type') }}</strong>
                                        </span>
                                    @endif
                                </div>
                                <div class="modal-footer">
                                    <button type="submit" class="btn btn-primary mt-4">{{ __('Save') }}</button>
                                   </div>
                                
                            </div>
      </form>
     

</div> 
                    </div>
                </div>
            </div>
        </div>
        <script>


document.addEventListener('DOMContentLoaded', function() {

    var leave_id = @json($leaveid);
    var val = @json('add');
    
    if(leave_id!=val){
        var values=@json($leave_req);
        $("#input-reason").val(values.reason);     
        $("#input-start").val(values.start);
        $("#input-end").val(values.end);
        $("#input-category").val(values.category);
        $("#input-type").val(values.type);
       
       
    }
    $("#input-leave_id").val(leave_id);
      
});

</script>
        @include('layouts.footers.auth')
    </div>
@endsection

@push('js')

    <script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.min.js"></script>
    <script src="{{ asset('argon') }}/vendor/chart.js/dist/Chart.extension.js"></script>

@endpush
<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Uuid;

class LeaveRequestController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $id = auth()->id();
        $leave_requests = DB::table('leave_requests')->where('request_by', '=', $id)->get();  
        $to_approve = DB::table('leave_requests')->where('approved_by', '=', $id)->get();
  
        return view('leave.view',  compact('leave_requests','to_approve'));
      
       
    }
    public static function get_user_name($user_id)
    {
        $user_=DB::table('users')->select('name')->where([['id', '=', $user_id],])->first();
        
        return $user_;
    }

    public static function reject(Request $request)
    {
        $leaveid=$request->requestId;
        DB::table('leave_requests')->where('id', '=',  $leaveid)->update(['status' =>'rejected']); 

        return redirect()->to('/leave'); 
      
        
    }
    public static function approve(Request $request)
    {
        $leaveid=$request->requestId;
        DB::table('leave_requests')->where('id', '=',  $leaveid)->update(['status' => 'approved']);

        return redirect()->to('/leave');    
    }

    /**
     * Store new events.
     *
     * @return \Illuminate\View\View
     * @param  \App\Http\Request   $request
     */
    public function store(Request $request)
    {
        
        $id = auth()->id();
        $doc = $request->file('leave_document');
        $manager_supervisor = DB::table('users')->where('id', '=', $id)->first();
        if($doc!=null){
            $uuid = Uuid::generate()->string;
            $leave_doc_name = $uuid.'.'.$doc->getClientOriginalExtension();
            $folder = '/uploads/leave_documents/';
            $filePath = $folder . $leave_doc_name;
            $this->uploadOne($doc, $folder, 'public', $leave_doc_name);
        }else{
            $leave_doc_name =null;
        } 
        if($request->leave_id_=="add"){
      
        DB::table('leave_requests')->insert([
            [
                'document_id'=>$leave_doc_name,
                'reason' => $request->reason,
                'start' =>$request->start,
                'end'=>$request->end,
                'request_by'=>$id,
                'approved_by'=>$manager_supervisor->supervisor_manager,
                'status'=>"pending",
                'category'=>$request->category,
                'type'=>$request->type,
                'created_at'=>now(),
            ],
        ]);
        }else{
            DB::table('leave_requests')->where('id', '=', $request->leave_id_)->update(
                array(
                    'document_id'=>$leave_doc_name,
                    'reason' => $request->reason,
                    'start' =>$request->start,
                    'end'=>$request->end,
                    'request_by'=>$id,
                    'approved_by'=>$manager_supervisor->supervisor_manager,
                    'category'=>$request->category,
                    'type'=>$request->type,
                    'updated_at'=>now(),
                )
            );
    

        }
       
        return redirect()->route('leave')->withStatus(__('Leave request successfully updated.'));
    }
    public static function destroy(Request $request)
    {
        $leaveid=$request->requestId;
        DB::table('leave_requests')->where('id', '=',  $leaveid)->delete();
        return redirect()->to('/leave'); 
    }
    

    public function index2(Request $request)
    {
        
        $leaveid=$request->requestId;
        
        if($leaveid=="add"){
            $leave_req =null;   
        }else{
            $leave_req = DB::table('leave_requests')->where('id', '=', $leaveid)->first();     
        }
       
        
        return view('leave.add_edit',compact('leaveid','leave_req'));
       
    }

     public function uploadOne(UploadedFile $uploadedFile, $folder = null, $disk = 'public', $filename = null)
    {
        $name = !is_null($filename) ? $filename : Str::random(25);

        $path =storage_path('uploads/leave_documents/'.$filename.'');

        if( Storage::exists($path)){
          
         Storage::disk('public')->delete('uploads/leave_documents/'.$filename.'');  
        }
        $file = $uploadedFile->storeAs($folder, $name, $disk);
      
        return $file;
    } 

      /**
     * Store new events.
     *
     * @return \Illuminate\View\View
     * 
     */
    public function download_file($file_name)
    {
        return response()->download(storage_path("app/public/uploads/leave_documents/{$file_name}"));
    }

}

Also there are other forms with document uploading function in my project which are working fine.
I search everywhere for solution,
also I delete composer.lock file , vendor directory and run composer install ,composer update again .
and also run clear cache,dump autoload commands too.
also check on vendor folder for illuminate/support files and they exists.

I don’t know what else to do,Please help !

my migrations,

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateLeaveRequestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('leave_requests', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('document_id')->nullable();
            $table->string('reason');
            $table->date('start');
            $table->date('end');
            $table->bigInteger('request_by')->unsigned();//emp_id
            $table->bigInteger('approved_by')->unsigned()->nullable();//emp_id
            $table->enum('status', ['approved','rejected','pending'])->default('pending');
            $table->enum('category', ['full day','half day','short leave'])->default('full day');
            $table->enum('type', ['no pay','casual'])->default('casual');
            $table->timestamps();
            $table->foreign('request_by')->references('id')->on('users');
            $table->foreign('approved_by')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('leave_requests');
    }
}

and

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateExpenseClaimTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('expense_claim', function (Blueprint $table) {
            $table->bigIncrements('claim_id');
            $table->date('date');
            $table->String('reason');
            $table->double('amount',10,2);
            $table->String('bill_id');
            $table->bigInteger('request_by')->unsigned();//emp_id
            $table->bigInteger('approved_by')->unsigned();//emp_id
            $table->enum('status', ['approved','rejected','pending'])->default('pending');
            $table->timestamps();
            $table->foreign('request_by')->references('id')->on('users');
            $table->foreign('approved_by')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('expense_claim');
    }
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *