Kanchan186

Kanchan186

Software Engineer at Pune

Member Since 2 Months Ago

Pune,Maharashtra

Experience Points
5,100
Total
Experience

4,900 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
5
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 2
5,100 XP
Oct
19
1 day ago
Activity icon

Started a new Conversation #1932 - Table 'phpmyadmin.pma__column_info' Doesn't Exist In Engine

please help me.. i don't know why this error occured in my phpmyadmin. and i also unable to export databse and reinstall xampp.

Oct
17
3 days ago
Activity icon

Started a new Conversation How To Create And Connect Android App With Laravel API

please suggests some tutorials

Oct
16
4 days ago
Activity icon

Started a new Conversation How To Write Common Web Services For Mobile Application In Laravel

please suggests me some tutorials with example or sample code to learn how to write web services

Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Retailer_other_infos.retailer_id' In 'where Clause' (SQL: Select * From `retailer_other_infos` Inner Join `head_offices` On `retailer_other_infos`.`ret_company_ho` = `head_offices`.`head_office_id`

RetailerDetailsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\City;
use App\Country;
use App\State;
use App\HeadOffice;
use App\Distributor;
use App\Retailer;
use App\RetailerOtherInfo;
use Session;
use File;

class RetailerDetailsController extends Controller
{
    public function show($retailer_id)
    {
        
//dd($retailer_id);
        $retailer=Retailer::where('retailers.retailer_id',$retailer_id)

        
         ->join('countries','retailers.ret_company_country','=','countries.country_id')
         ->join('states','retailers.ret_company_state','=','states.state_id')
         ->join('cities','retailers.ret_company_city','=','cities.city_id')
         ->get();

   $RetailerOtherInfo=RetailerOtherInfo::where(' retailer_other_infos.retailer_id',$retailer_id)
    
   ->join('head_offices','retailer_other_infos.ret_company_ho','=','head_offices.head_office_id')->get();
    
   // $RetailerOtherInfo=RetailerOtherInfo::get();
        return view('backend.retailer_details.viewRetailerDetails',compact('retailer','RetailerOtherInfo'));
     }

}

Oct
15
5 days ago
Activity icon

Started a new Conversation Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`retailers`, CONSTRAINT `retailers_distributor_id_foreign` FOREIGN KE

<?php

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

class CreateRetailersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('retailers', function (Blueprint $table) {
            $table->increments('retailer_id');
            $table->string('ret_company_name');
            $table->integer('ret_company_mobile')->unique();
            $table->string('ret_company_email')->unique();
            $table->string('ret_company_address');
            $table->string('ret_company_photo');
            $table->string('username');
            $table->string('password');
            $table->integer('ret_company_state');
            $table->integer('ret_company_city');
            $table->integer('ret_company_country');
            $table->integer('ret_company_pincode');
            $table->string('ret_company_code');
            $table->string('ret_contact_person');
            $table->integer('ret_login_first');
            $table->timestamps();
        });

    Schema::table('retailers', function (Blueprint $table) {
            $table->integer('distributor_id')->unsigned();
            $table->foreign('distributor_id')->references('distributor_id')->on('distributors')->onDelete('cascade')->change();
            
            
        });
        


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('retailers');
        Schema::table('retailers', function (Blueprint $table) {
             $table->dropForeign('retailers_distributor_id_foreign');
            
        });
    }
}
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'emp_id' Cannot Be Null (SQL: Insert Into `distributors`

@nakov yes sir

i am using this

public function __construct()
    {
        $this->middleware('auth');
    }
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'emp_id' Cannot Be Null (SQL: Insert Into `distributors`

@nakov yes sir i want to store ID of the currently logged in user. auth()->id() to database in distributor table in emp_id field, how to do that?

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'emp_id' Cannot Be Null (SQL: Insert Into `distributors`

i am employee, i am logged in to the session and on this session i want to store distributors info, means i want to store session id in distributors table as emp_id.

how can i do this?

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'emp_id' Cannot Be Null (SQL: Insert Into `distributors`

how can i store the session id in distributors tables? how to set the session please suggests me some tutorials

Activity icon

Started a new Conversation SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'emp_id' Cannot Be Null (SQL: Insert Into `distributors`

DistributorController.php

public function store(Request $request)
    {
        //dd(request()->all());
        //dd(session()->all());
         $this->validate($request,[
                                'dist_company_name'=>'unique:distributors|required',
                               
                                ]);

         if($request->hasFile('dist_company_photo')){
            

            $file = $request->file('dist_company_photo');

            $destinationPath = public_path().'/dist_company_photos/';
            $filename = $file->getClientOriginalName();
            if(!File::exists($destinationPath))
             {
                File::makeDirectory($destinationPath, $mode = 0777, true);
                $file->move($destinationPath, $filename);
             }
             else
             {
                $file->move($destinationPath, $filename);
             }
            
 //dd($filename);
         //   echo  $filename;exit;
            }//end of if
           


            $distributor_id=Distributor::create([
            
            
            'emp_id'=>session()->get('id'), 
            'dist_company_name' => request('dist_company_name'),
            'dist_company_email' => request('dist_company_email'),
            'dist_company_mobile' => request('dist_company_mobile'),
            'dist_company_state' => request('dist_company_state'),
            'dist_company_city' => request('dist_company_city'),
            'dist_company_pincode' => request('dist_company_pincode'),
            'dist_company_country' => request('dist_company_country'),
            'dist_company_address' => request('dist_company_address'),
            'dist_company_photo' => $filename,
            'dist_company_code' => request('dist_company_code'),
            'dist_contact_person'=>request('dist_contact_person'),
            'username' => request('username'),
            'password' => request('password'),
            'login_first' => 0,

            ]);
              
         //dd($distributor_id);

            if($distributor_id->distributor_id!=null)
            {
                //dd('hi');
                DistributorOtherInfos::create([
            'dist_company_currency' => request('dist_company_currency'),
            'dist_company_ifsc' => request('dist_company_ifsc'),
            'dist_company_acc_no' => request('dist_company_acc_no'),
            'dist_company_bank' => request('dist_company_bank'),
            'dist_company_pan' => request('dist_company_pan'),
            'dist_company_gst' => request('dist_company_gst'),
            'dist_company_cin' => request('dist_company_cin'),
            'dist_program_tag_line' => request('dist_program_tag_line'),
            'dist_program_title' => request('dist_program_title'),
            'dist_program_type' => request('dist_program_type'),
            'dist_company_ho' => request('dist_company_ho'),
            'distributor_id' => $distributor_id->distributor_id
                
            ]);


        }
        return redirect('distributor/view');
    }
Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'distributor_other_infos. Dist_company_ho' In 'on Clause' (SQL: Select * From `distributor_other_infos` Inner Join `head_offices` On `distributor_other_infos`.` Dist_company_ho` = `head_offices`.`head

DistributorDetailController.php

public function show($distributor_id)
    {
        
//dd($distributor_id);
        $distributor=Distributor::where('distributors.distributor_id',$distributor_id)

        
         ->join('countries','distributors.dist_company_country','=','countries.country_id')
         ->join('states','distributors.dist_company_state','=','states.state_id')
         ->join('cities','distributors.dist_company_city','=','cities.city_id')
         ->get();

     $DistributorOtherInfos=DistributorOtherInfos::where('distributor_other_infos.distributor_id',$distributor_id)
    
    ->join('head_offices','distributor_other_infos. dist_company_ho','=','head_offices.head_office_id')->get();
 
   //$DistributorOtherInfos=DistributorOtherInfos::get();
     
     
       $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city = City::all();
        $country=Country::get();


        return view('backend.distributor_details.viewdistdetail',compact('distributor','country','HeadOffice','state','city','DistributorOtherInfos'));
     }
Oct
11
1 week ago
Activity icon

Replied to SQLSTATE[HY000]: General Error: 1364 Field 'user_id' Doesn't Have A Default Value (SQL: Insert Into `distributors`

$user_id=$request->session()->get('user_id'),

can i use like this? to store data using session

Activity icon

Started a new Conversation SQLSTATE[HY000]: General Error: 1364 Field 'user_id' Doesn't Have A Default Value (SQL: Insert Into `distributors`

DistributorController.php

public function store(Request $request, Distributor $distributor_id)
    {
        //dd(request()->all());
         $this->validate($request,[
                                'dist_company_name'=>'unique:distributors|required',
                               
                                ]);

         if($request->hasFile('dist_company_photo')){
            

            $file = $request->file('dist_company_photo');

            $destinationPath = public_path().'/dist_company_photos/';
            $filename = $file->getClientOriginalName();
            if(!File::exists($destinationPath))
             {
                File::makeDirectory($destinationPath, $mode = 0777, true);
                $file->move($destinationPath, $filename);
             }
             else
             {
                $file->move($destinationPath, $filename);
             }
            
 //dd($filename);
         //   echo  $filename;exit;
            }//end of if
           


            $distributor_id=Distributor::create([
            
            'user_id'=>Session::put('user_id', $distributor_id->user_id),
            // $request->session()->put('user_id','1'),
            'dist_company_name' => request('dist_company_name'),
            'dist_company_email' => request('dist_company_email'),
            'dist_company_mobile' => request('dist_company_mobile'),
            'dist_company_state' => request('dist_company_state'),
            'dist_company_city' => request('dist_company_city'),
            'dist_company_pincode' => request('dist_company_pincode'),
            'dist_company_country' => request('dist_company_country'),
            'dist_company_address' => request('dist_company_address'),
            'dist_company_photo' => $filename,
            'dist_company_code' => request('dist_company_code'),
            'dist_contact_person'=>request('dist_contact_person'),
            'username' => request('username'),
            'password' => request('password'),
            'login_first' => 0,

            ]);
              
         // dd($distributor_id);

            if($distributor_id->distributor_id!=null)
            {
                //dd('hi');
                distributor_other_infos::create([
            'dist_company_currency' => request('company_currency'),
            'dist_company_ifsc' => request('company_ifsc'),
            'dist_company_acc_no' => request('company_acc_no'),
            'dist_company_bank' => request('company_bank'),
            'dist_company_pan' => request('company_pan'),
            'dist_company_gst' => request('company_gst'),
            'dist_company_cin' => request('company_cin'),
            'dist_program_tag_line' => request('program_tag_line'),
            'dist_program_title' => request('program_title'),
            'dist_program_type' => request('program_type'),
            'dist_company_ho' => request('company_ho'),
            'dist_company_id' => $company_id->company_id
                
            ]);


        }
        return redirect('distributor/view');
    }

how to store session to database

Activity icon

Replied to How To Store Session To Database

how it can be happened in create in store function

Activity icon

Started a new Conversation How To Store Session To Database

i want to store employee information on specific id and this id is user_id, when i login to session through user_id it becomes session id and on that session id i want to store employee information

Oct
10
1 week ago
Activity icon

Started a new Conversation ErrorException (E_ERROR) Undefined Variable: Department (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\employee_zone_mapping\editempzone.blade.php)

editempzone.blade.php

<form method="post" action="{{url('/')}}/employee_zone_mapping/{{$empzonemapping->empzone_id}}">
                                {{method_field('PATCH')}}{{csrf_field()}}

                                    <div class="form-group">
                                        <h5>Department<span class="text-danger">*</span></h5>
                                        <div class="controls">
                                          <select class="form-control" name="department_id"  required>  
                                        
                                            @foreach($department as $br)
                                            
                                                @if($br->department_id == $empzonemapping->department_id )
                                                     <option value="{{$br->department_id}}" selected >{{$br->department_name}}</option>
                                                @else
                                                     <option value="{{$br->department_id}}">{{$br->department_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <h5>Designation<span class="text-danger">*</span></h5>
                                        <div class="controls">
                                          <select class="form-control" name="designation_id"  required>  
                                    
                                        @foreach($designation as $br)
                                            
                                                @if($br->designation_id == $empzonemapping->designation_id )
                                                     <option value="{{$br->designation_id}}" selected >{{$br->designation_name}}</option>
                                                @else
                                                     <option value="{{$br->designation_id}}">{{$br->designation_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>

                                        </div>
                                    </div>

                                
                                <div class="form-group">
                                        <h5>Employee Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="emp_id" required>
                                                <option>--Select Employee--</option>
                                            @foreach($employee as $br)
                                            <option value="{{$br->emp_id}}">{{$br->emp_fname}}  {{$br->emp_lname}}</option>
                                            @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>




                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Zone Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="zone_id" required>
                                            @foreach($zone as $br)
                                            
                                                @if($br->zone_id == $empzonemapping->zone_id )
                                                     <option value="{{$br->zone_id}}" selected >{{$br->zone_name}}</option>
                                                @else
                                                     <option value="{{$br->zone_id}}">{{$br->zone_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div> 

                                            <div class="box-footer">
                                    <div class="col-sm-3 control-label"></div>
                                        <div class="col-sm-8">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-default" type="reset">Reset</button>
                                        </div>
                                    </div><!-- /.box-footer -->
                                </form>

empzoneController.php

public function edit(EmpzoneMapping $empzone_id)
  {
    $empzonemapping=EmpzoneMapping::where('empzone_mappings.empzone_id',$empzone_id->empzone_id)

         ->join('departments','empzone_mappings.department_id','=','departments.department_id')
         ->join('designations','empzone_mappings.designation_id','=','designations.designation_id')
         ->join('employees','empzone_mappings.emp_id','=','employees.emp_id')
         ->join('zones','empzone_mappings.zone_id','=','zones.zone_id')

         ->select('zone_name','emp_fname','emp_lname','department_name','designation_name','empzone_mappings.*')->first();


   // $department=Department::get();
    $designation=designation::get();
    $zone=Zone::get();
    $employee=Employee::get();
    //$empzonemapping=EmpzoneMapping::get();
   


    return view('backend.employee_zone_mapping.editempzone',compact('empzonemapping','employee','designation','zone'));
  }

  public function update(Request $req,EmpzoneMapping $empzonemapping)
  {

    $empzonemapping->update($req->all());

   return redirect('employee_zone_mapping/view');

  }

Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Departments.department_id' In 'on Clause' (SQL: Select * From `empzone_mappings` Inner Join `departments` On `empzone_mappings`.`department_id` = ` Departments`.`department_id` Inner Join `designati

empzoneControlller.php

public function show()
  {
    $empzonemapping=EmpzoneMapping::join('departments','empzone_mappings.department_id','=','                              departments.department_id')
                                  ->join('designations','empzone_mappings.designation_id','=','designations.designation_id')
                                  ->join('employees','empzone_mappings.emp_id','=','employees.emp_id')
                                  ->join('zones','empzone_mappings.zone_id','=','zones.zone_id')
                                  ->get();

    $department=Department::get();
    $designation=designation::get();
    $zone=Zone::get();
    $employee=Employee::get();
    $empzonemapping=EmpzoneMapping::get();
    
    //return $names;

   return view('backend.employee_zone_mapping.viewempzone',compact('empzonemapping','employee','department','designation','zone'));
  }

viewempzone.blade.php

 <div class="table-responsive m-t-40">
                                    <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                               <th>Sr No</th>
                                                 <th>department</th>            <th>designation </th>
                                                 <th>Employee Name</th>
                                                 <th>Zone</th>
                                                <th>Operations</th>
                                            </tr>
                                        </thead>
                                        
                                        <tbody>

                                          <?php $i=1; ?>
                                          @foreach($empzonemapping as $br)

                                            <tr>
                                            <td>{{$i++}}</td>
                                            <td>{{$br->department_name}}</td>
                                            <td>{{$br->designation_name}}</td>
                                            <td>{{$br->emp_fname}} {{$br->emp_lname}}</td>
                                            <td>{{$br->zone_name}}</td>   

                                                <td>
                                                  <a href="{{url('/')}}/employee_zone_mapping/{{$br->empzone_id}}/edit"><i class="fas fa-edit"></i></a> 

                                                  &nbsp;<a href="{{url('/')}}/employee_zone_mapping/{{$br->empzone_id}}" onclick="return confirm('Do you want delete this record')"><i class="fas fa-trash" ></i>
                                                </td>
                                            </tr>

                                           @endforeach
                                            
                                        </tbody>
                                    </table>
                                </div>
Oct
07
1 week ago
Activity icon

Started a new Conversation Trying To Get Property 'sarea_id' Of Non-object (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\statearea\editStatearea.blade.php)

StateareaController.php

public function edit(StateArea $sarea_id)
    {
        //dd('hi');
        //dd($sarea_id);
        $statearea=StateArea::where('state_areas.sarea_id',$sarea_id->sarea_id)
                            
                            ->join('zones','state_areas.zone_id','=','zones.zone_id')
                            ->join('regions','state_areas.region_id','=','regions.region_id')
                            ->join('countries','state_areas.country_id','=','countries.country_id')
                            ->join('states','state_areas.state_id','=','states.state_id')
                            ->join('areas','state_areas.area_id','=','areas.area_id')
                            ->join('cities','state_areas.city_id','=','cities.city_id')
                            

                            ->select('zone_name','area_name','city_name','region_name','countries.country_name as country_name','states.state_name as state_name',
                                'state_areas.*')->first();
        $zone=Zone::get();
        $country=Country::get();
        $state=State::get();
        $area=area::get();
        $city=city::get();
        


        //dd($statearea);
        return view('backend.statearea.editStatearea',compact('statearea','zone','country','state','area','city'));
    }

  public function update(Request $req,StateArea $sarea_id)
    {
        //dd($req);
        $country_id=request('country_id');
        $zone_id=request('zone_id');
        $region_id=request('region_id');
        $state_id=request('state_id');
        $area_id=request('area_id');
        $city_id=request('city_id');
        
        $sarea_id->update($req->all());
        //dd($zone_id);
        return redirect('statearea/view/'.$region_id.'/'.$zone_id.'/'.$area_id);
    }

editStatearea.blade.php

 <form method="post" action="{{url('/')}}/statearea/{{$statearea->sarea_id}}">
                                {{method_field('PATCH')}}{{csrf_field()}}
                                    

                          <div class="form-group">
                          <label for="inputPassword3" class="col-sm-3 control-label">Country Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="country_id" required>
                                            @foreach($country as $br)
                                            
                                                @if($br->id == $statearea->country_id )
                                                     <option value="{{$br->country_id}}" selected >{{$br->country_name}}</option>
                                                @else
                                                     <option value="{{$br->country_id}}">{{$br->country_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>


                                    <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label">Zone Name 
                <span class="required"> * </span></label>
                <div class="col-sm-8">
                                        <select class="form-control" name="zone_id" required>
                                            @foreach($zone as $br)
                                            
                                        @if($br->zone_id == $statearea->zone_id )
                         <option value="{{$br->zone_id}}" selected >{{$br->zone_name}}</option>
                        @else
            <option value="{{$br->zone_id}}">{{$br->zone_name}}</option>
                     @endif

                                            @endforeach
                                        </select>
                            </div>
                    </div>

                        <div class="form-group">
                    <label for="inputPassword3" class="col-sm-3 control-label">Region Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
 <input type="text" class="form-control" id="region_name" placeholder="" name="region_name" value="{{ $statearea->region_name}}"required>
        <input type="hidden" name="region_id" value="{{ $statearea->region_id}}">
                                        </div>
                                    </div>

                                    
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">State Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="state_id" required>
                                            @foreach($state as $br)
                                            
                                                @if($br->id == $statearea->state_id )
                                                     <option value="{{$br->state_id}}" selected >{{$br->state_name}}</option>
                                                @else
                                                     <option value="{{$br->state_id}}">{{$br->state_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Area Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <input type="text" class="form-control" id="area_name" placeholder="" name="area_name" value="{{ $statearea->area_name}}"required>
                                        <input type="hidden" name="area_id" value="{{ $statearea->area_id}}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">City Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="state_id" required>
                                            @foreach($city as $br)
                                            
                                                @if($br->id == $statearea->city_id )
                                                     <option value="{{$br->city_id}}" selected >{{$br->city_name}}</option>
                                                @else
                                                     <option value="{{$br->city_id}}">{{$br->city_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    



                                    <div class="box-footer">
                                    <div class="col-sm-3 control-label"></div>
                                        <div class="col-sm-8">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-default" type="reset">Reset</button>
                                        </div>
                                    </div><!-- /.box-footer -->
                                </form>
Activity icon

Started a new Conversation Property [sarea_id] Does Not Exist On This Collection Instance. (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\statearea\editStatearea.blade.php)

editStatearea.php

<form method="post" action="{{url('/')}}/statearea/{{$statearea->sarea_id}}">
                                {{method_field('PATCH')}}{{csrf_field()}}
                                    

                                  <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Country Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="country_id" required>
                                            @foreach($country as $br)
                                            
                                                @if($br->id == $statearea->country_id )
                                                     <option value="{{$br->country_id}}" selected >{{$br->country_name}}</option>
                                                @else
                                                     <option value="{{$br->country_id}}">{{$br->country_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Zone Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="zone_id" required>
                                            @foreach($zone as $br)
                                            
                                                @if($br->zone_id == $statearea->zone_id )
                                                     <option value="{{$br->zone_id}}" selected >{{$br->zone_name}}</option>
                                                @else
                                                     <option value="{{$br->zone_id}}">{{$br->zone_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Region Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <input type="text" class="form-control" id="region_name" placeholder="" name="region_name" value="{{ $statearea->region_name}}"required>
                                        <input type="hidden" name="region_id" value="{{ $statearea->region_id}}">
                                        </div>
                                    </div>

                                    
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">State Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="state_id" required>
                                            @foreach($state as $br)
                                            
                                                @if($br->id == $statearea->state_id )
                                                     <option value="{{$br->state_id}}" selected >{{$br->state_name}}</option>
                                                @else
                                                     <option value="{{$br->state_id}}">{{$br->state_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Area Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <input type="text" class="form-control" id="area_name" placeholder="" name="area_name" value="{{ $statearea->area_name}}"required>
                                        <input type="hidden" name="area_id" value="{{ $statearea->area_id}}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">City Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="state_id" required>
                                            @foreach($city as $br)
                                            
                                                @if($br->id == $statearea->city_id )
                                                     <option value="{{$br->city_id}}" selected >{{$br->city_name}}</option>
                                                @else
                                                     <option value="{{$br->city_id}}">{{$br->city_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>

                                    



                                    <div class="box-footer">
                                    <div class="col-sm-3 control-label"></div>
                                        <div class="col-sm-8">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-default" type="reset">Reset</button>
                                        </div>
                                    </div><!-- /.box-footer -->
                                </form>

StateareaController.php

public function edit(StateArea $sarea_id)
    {
        //dd('hi');
        //dd($sarea_id);
        $statearea=StateArea::where('state_areas.sarea_id',$sarea_id->sarea_id)
                            
                            ->join('zones','state_areas.zone_id','=','zones.zone_id')
                            ->join('regions','state_areas.region_id','=','regions.region_id')
                            ->join('countries','state_areas.country_id','=','countries.country_id')
                            ->join('states','state_areas.state_id','=','states.state_id')
                            ->join('areas','state_areas.area_id','=','areas.area_id')
                            ->join('cities','state_areas.city_id','=','cities.city_id')
                            

                            ->select('zone_name','area_name','city_name','region_name','countries.country_name as country_name','states.state_name as state_name',
                                'state_areas.*')->first();
        $zone=Zone::get();
        $country=Country::get();
        $state=State::get();
        $area=area::get();
        $city=city::get();
        $statearea=StateArea::get();


        //dd($statearea);
        return view('backend.statearea.editStatearea',compact('statearea','zone','country','state','area','city'));
    }

  public function update(Request $req,StateArea $sarea_id)
    {
        //dd($req);
        $country_id=request('country_id');
        $zone_id=request('zone_id');
        $region_id=request('region_id');
        $state_id=request('state_id');
        $area_id=request('area_id');
        $city_id=request('city_id');
        
        $sarea_id->update($req->all());
        //dd($zone_id);
        return redirect('statearea/view/'.$region_id.'/'.$zone_id.'/'.$area_id);
    }
Oct
04
2 weeks ago
Activity icon

Replied to Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) R

lluminate \ Database \ QueryException (23000)
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) REFERENCES `zones` (`zone_id`) ON DELETE CASCADE) (SQL: insert into `areas` (`zone_id`, `state_id`, `area_name`, `updated_at`, `created_at`) values (11, 14, area1, 2019-10-04 22:35:25, 2019-10-04 22:35:25))
Activity icon

Replied to Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) R

@munazzil when i update and migrate table again error occured

Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `db_partsanalysis`.`areas` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `areas` add constraint `areas_zone_id_foreign` foreign key (`zone_id`) references `zones` (`zone_id`) on delete cascade)
Activity icon

Replied to Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) R

area.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class area extends Model
{
    protected $fillable =['area_name','zone_id','state_id'];
    protected $primaryKey = 'area_id';
}
Activity icon

Replied to Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) R

zones table

<?php

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

class CreateZonesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('zones', function (Blueprint $table) {
            $table->increments('zone_id');
            $table->string('zone_name');
            $table->timestamps();
        });
    }

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

Activity icon

Started a new Conversation Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`areas`, CONSTRAINT `areas_zone_id_foreign` FOREIGN KEY (`zone_id`) R

areas table

<?php

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

class CreateAreasTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('areas', function (Blueprint $table) {
            $table->increments('area_id');
            $table->string('area_name');
            $table->timestamps();
        });

         Schema::table('areas', function (Blueprint $table) {
            $table->integer('zone_id')->unsigned()->after('area_id');
            $table->foreign('zone_id')->references('zone_id')->on('zones')->onDelete('cascade')->change();

            $table->integer('state_id')->unsigned()->after('area_id');
            $table->foreign('state_id')->references('state_id')->on('states')->onDelete('cascade')->change();
           
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
       Schema::dropIfExists('areas');
         Schema::table('areas', function (Blueprint $table) {
          
            $table->dropForeign('areas_zone_id_foreign');
            $table->dropForeign('areas_state_id_foreign');
        });
    }
}

AreaController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Zone;
use App\Region;
use App\State;
use App\Country;
use App\RegionArea;
use App\city;
use App\area;
use App\StateArea;

class AreaController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {
        $zone=Zone::get();
        $state=State::get();
        $country=Country::get();
        $city=city::get();
        $region=region::get();
        return view('backend.area.addarea',compact('zone','region','state','country','city'));
    }

public function store(Request $request)
    {
        //dd(request()->all());
         $this->validate($request,[
                                'area_name'=>'unique:areas|required',
                                'zone_id'=>'required',
                                'state_id'=>'required',
                                
                               
                                ]);
        $area_info=area::create([
        'zone_id' => request('zone_id'),
        'state_id'=> request('state_id'),
        'area_name' => request('area_name'),
        
        ]);
    dd($area_info);
        if(isset($area_info))
        {
            $i=0;
            $area=request('state_area');
            //echo count(request('region_area'));
            for($i=0;$i<count(request('state_area'));$i++)
            {
                //echo $area[$i];
                StateArea::create([
                        'zone_id' => request('zone_id'),
                        'region_id'=>request('region_id'),
                        'area_id'=>$area_info->area_id,
                        'country_id' => request('company_country'),
                        'state_id'=> request('company_state'),
                        'city_id'=> $area[$i]
                        ]);
            }
        }
        //dd('hi');
        return redirect('area/view');
    }

}
Oct
03
2 weeks ago
Activity icon

Started a new Conversation Emp_photo Stores In Database But Not In Public/emp_photos Folder

public function update(Request $req,Employee $employee)
    {

        if($req->hasFile('emp_photo')){
            
            $files=public_path().'/emp_photos/'.$req->input('emp_photo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('emp_photo');

            $destinationPath = public_path().'/emp_photos/';
            $filename = $file->getClientOriginalName();
            $file->move($destinationPath, $filename);
            
            
           // echo  $filename;
            }
            else{
                $filename=$req->input('emp_photo1');
            }

      
        $employee->update($req->all());

        return redirect('employee/view');

    }
Activity icon

Started a new Conversation Update Image In Database But Not In Folder In Laravel

please tell me where i going wrong

public function update(Request $request, Company $company,CompanyOtherInfo $CompanyOtherInfo ) 

    {
        //dd($company);
        //dd(request()->all());

       if($request->hasFile('company_photo')){
            
            $files=public_path().'/company_photos/'.$req->input('company_photo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('company_photo');

            $destinationPath = public_path().'/company_photos/';
            $filename = $file->getClientOriginalName();
            $file->move($destinationPath, $filename);
            

            
           // echo  $filename;
            }
            else{
                $filename=$request->input('company_photo1');
            }
//dd($request);
//dd($filename);

      $company::where('companies.company_id',$company->company_id)
                       ->update([

           'company_photo' => $filename,            
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_country' => request('company_country'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_address' => request('company_address'),
            'industry_id' => request('industry_id'),
            'segment_id' => request('segment_id'),
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            

            ]);
Activity icon

Started a new Conversation When Update An Image It Takes Only Image From Emp_photos Folder From Public Folder Not From Other Place Like Desktop Or Other Drives

public function update(Request $req,Employee $employee)
    {

        if($req->hasFile('emp_photo')){
            
            $files=public_path().'/emp_photos/'.$req->input('emp_photo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('emp_photo');

            $destinationPath = public_path().'/emp_photos/';
            $filename = $file->getClientOriginalName();
            $file->move($destinationPath, $filename);

            
           // echo  $filename;
            }
            else{
                $filename=$req->input('emp_photo1');
            }

       

        $employee->update($req->all());

        return redirect('employee/view');

    }
Activity icon

Started a new Conversation SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'company_photo' Cannot Be Null

editCompany.blade.php

<div class="form-group">
                                         <h5>Company Logo<span class="text-danger">*</span></h5>
                                         <img src="{{url('/')}}/company_photo/{{$company->company_photo}}" height="100px" width="100px" >
                                       <input type="file"  name="company_photo1" value="{{$company->company_photo}}">
                                         <input type="file" id="input-file-now-custom-1" name="company_photo" class="dropify" >
                                         
                                         
                                     </div>

CompanyController.php

public function update(Request $request, Company $company,CompanyOtherInfo $CompanyOtherInfo ) 

    {
        //dd($company);
       if($request->hasFile('company_photo')){
            
            $files=public_path().'/company_photo/'.$req->input('company_photo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('company_photo');

            $destinationPath = public_path().'/company_photo/';
           $filename= Input::file('company_photo')->getClientOriginalName();
            $file->move($destinationPath, $filename);

            
           // echo  $filename;
            }
            else{
                $filename=$request->input('company_photo1');
            }

      $company::where('companies.company_id',$company->company_id)
                       ->update([

           'company_photo' => $filename,            
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_country' => request('company_country'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_address' => request('company_address'),
            'industry_id' => request('industry_id'),
            'segment_id' => request('segment_id'),
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            

            ]);

      $CompanyOtherInfo::where('company_other_infos.company_id',$company->company_id)
                      ->update([
            'company_currency' => request('company_currency'),
            'company_ifsc' => request('company_ifsc'),
            'company_acc_no' => request('company_acc_no'),
            'company_bank' => request('company_bank'),
            'company_pan' => request('company_pan'),
            'company_gst' => request('company_gst'),
            'company_cin' => request('company_cin'),
            'program_tag_line' => request('program_tag_line'),
            'program_title' => request('program_title'),
            'program_type' => request('program_type'),
            'company_ho' => request('company_ho')
                
            ]);
        
    return redirect('company/view');

    }
Oct
02
2 weeks ago
Activity icon

Replied to Undefined Variable: Filename

error not occurred in this code.. but image not updated

public function update(Request $request, Company $company) 

    {
        //dd($company);
       if($request->hasFile('company_photo')){
            
            $files=public_path().'/company_photo/'.$req->input('company_photo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('company_photo');

            $destinationPath = public_path().'/company_photo/';
            $filename = $file->getClientOriginalName();
            $file->move($destinationPath, $filename);

            
           // echo  $filename;
            }
            else{
                $filename=$request->input('company_photo1');
            }

      company::where('companies.company_id',$company->company_id)
                       ->update([

           'company_photo' => $filename,            
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_country' => request('company_country'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_address' => request('company_address'),
            'industry_id' => request('industry_id'),
            'segment_id' => request('segment_id'),
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            

            ]);

      CompanyOtherInfo::where('company_other_infos.company_id',$company->company_id)
                      ->update([
            'company_currency' => request('company_currency'),
            'company_ifsc' => request('company_ifsc'),
            'company_acc_no' => request('company_acc_no'),
            'company_bank' => request('company_bank'),
            'company_pan' => request('company_pan'),
            'company_gst' => request('company_gst'),
            'company_cin' => request('company_cin'),
            'program_tag_line' => request('program_tag_line'),
            'program_title' => request('program_title'),
            'program_type' => request('program_type'),
            'company_ho' => request('company_ho')
                
            ]);
        
    return redirect('company/view');

    }
Activity icon

Replied to Undefined Variable: Filename

public function update(Request $request, Company $company) 

    {
        //dd($company);
       if($request->hasFile('company_photo')){
            

            $file = $request->file('company_photo');

            $destinationPath = public_path().'/company_photo/';
            $filename = $file->getClientOriginalName();
            if(!File::exists($destinationPath))
             {
                File::makeDirectory($destinationPath, $mode = 0777, true);
                $file->move($destinationPath, $filename);
             }
             else
             {
                $file->move($destinationPath, $filename);
             }
            

         //   echo  $filename;exit;
            }

      company::where('companies.company_id',$company->company_id)
                       ->update([

            'company_photo' => $filename,               
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_country' => request('company_country'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_address' => request('company_address'),
            'industry_id' => request('industry_id'),
            'segment_id' => request('segment_id'),
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            

            ]);

      CompanyOtherInfo::where('company_other_infos.company_id',$company->company_id)
                      ->update([
            'company_currency' => request('company_currency'),
            'company_ifsc' => request('company_ifsc'),
            'company_acc_no' => request('company_acc_no'),
            'company_bank' => request('company_bank'),
            'company_pan' => request('company_pan'),
            'company_gst' => request('company_gst'),
            'company_cin' => request('company_cin'),
            'program_tag_line' => request('program_tag_line'),
            'program_title' => request('program_title'),
            'program_type' => request('program_type'),
            'company_ho' => request('company_ho')
                
            ]);
        
    return redirect('company/view');

    }

i tried this code but still same error

Activity icon

Started a new Conversation Undefined Variable: Filename

CompanyController.php

public function update(Request $request, Company $company) 

    {
        //dd($company);


      company::where('companies.company_id',$company->company_id)
                       ->update([
                        
            'company_photo' => $filename,               
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_country' => request('company_country'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_address' => request('company_address'),
            'industry_id' => request('industry_id'),
            'segment_id' => request('segment_id'),
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            

            ]);

      CompanyOtherInfo::where('company_other_infos.company_id',$company->company_id)
                      ->update([
            'company_currency' => request('company_currency'),
            'company_ifsc' => request('company_ifsc'),
            'company_acc_no' => request('company_acc_no'),
            'company_bank' => request('company_bank'),
            'company_pan' => request('company_pan'),
            'company_gst' => request('company_gst'),
            'company_cin' => request('company_cin'),
            'program_tag_line' => request('program_tag_line'),
            'program_title' => request('program_title'),
            'program_type' => request('program_type'),
            'company_ho' => request('company_ho')
                
            ]);
        
    return redirect('company/view');

    }
Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

okk sir can u please share me the link of documentation where i learn how to update two differnt table at same time using where in update

Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

@nakov sir program_type is in company_other_infos table

error occurred when i write {{$companyOtherInfo->program_type}}

Property [program_type] does not exist on this collection instance. (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\company\editCompany.blade.php)
Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

@nakov sir, please check my editCompany.blade.php

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'program_type' in 'field list' (SQL: update `companies` set `company_code` = gol, `updated_at` = 2019-10-02 20:38:22, `program_type` = z where `company_id` = 9)
<input type="text" name="program_type" id ="program_type" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->program_type}}"> 

$company->program_type is correct?

to fetch data from CompanyOtherInfo

Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

problem is that fields from companyOtherInfo are not updated like program_type

Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

company_other_infos is another table which contails company extra details

companyOtherInfo is model

CompanyOtherInfo.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class CompanyOtherInfo extends Model
{
    protected $fillable =['company_id','company_currency','company_ifsc','company_acc_no','company_bank','company_pan','company_gst','company_cin','company_ho','program_tag_line','program_title','program_type'];
    protected $primaryKey = 'company_info_id';
}
Activity icon

Replied to Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

company.php

<?php

namespace App;


use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    protected $fillable =['company_name','industry_id','company_mobile','company_email','company_address','company_photo','username','password','company_state','company_city','company_country','company_pincode','company_code','login_first','segment_id','contact_person','company_currency','company_ifsc','company_acc_no','company_bank','company_pan','company_gst','company_cin','company_HO','program_tag_line','program_title','program_type'];
    protected $primaryKey = 'company_id';


}
Activity icon

Started a new Conversation Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call To A Member Function Update() On Null

CompanyController.php

public function edit($company_id)
    {
        //dd($company);

        $company=company::findOrFail($company_id);
        $industry=Industry::get();
        $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city=City::where('state_id',$company->company_state)->get();
        $segment=Segment::get();
        $HeadOffice=HeadOffice::get();
        //$CompanyOtherInfo=CompanyOtherInfo::get();

        $CompanyOtherInfo=CompanyOtherInfo::where('company_other_infos.company_id',$company_id)->get();

        //dd($industry);
        //dd($HeadOffice);
        //dd($program_type);
        return view('backend.company.editCompany',compact('company','industry','state','city','segment','HeadOffice','CompanyOtherInfo'));
    }

    public function update(Request $request, Company $company) 
    {
        //dd($request->all());
       $company->update($request->all());
       $company->companyOtherInfo->update($request->all());
        
    return redirect('company/view');

    }
   
   public function destroy(Company $company)
    {
        $company->delete();
        return redirect('company/view');
    }
}

editCompany.blade.php

<div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Edit Company</h4>
                                <h6 class="card-subtitle"></h6>
                                @if ($errors->any())
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif
                               <form method="post" action="{{url('/')}}/company/{{$company->company_id}}">
                                {{method_field('PATCH')}}{{csrf_field()}}
                               
                                     <div class="form-group">
                                        <h5>Company Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_name" id ="company_name" class="form-control" value="{{ $company->company_name}}" required data-validation-required-message="This field is required"> </div>
                                       
                                    </div>

                                    
                                    <div class="form-group">
                                        <h5>Company Email <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_email" id ="company_email" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_email}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Company mobile <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_mobile" id ="company_mobile" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_mobile}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Select State <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="company_state" id="company_state" onchange="getCity(this.value)" required>
                                                     <option>--Select State--</option>
                                             @foreach($state as $br)
                                            
                                                @if($br->state_id == $company->company_state )
                                                     <option value="{{$br->state_id}}" selected >{{$br->state_name}}</option>
                                                @else
                                                     <option value="{{$br->state_id}}">{{$br->state_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Select City <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="company_city" id="company_city" required>
                                                @foreach($city as $br)
                                            
                                                @if($br->city_id == $company->company_city )
                                                     <option value="{{$br->city_id}}" selected >{{$br->city_name}}</option>
                                                @else
                                                     <option value="{{$br->city_id}}">{{$br->city_name}}</option>
                                                @endif

                                            @endforeach
                                            
                                        </select>

                                        </div>
                                       
                                    </div>
                                     <div class="form-group">
                                        <h5>Company Address <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <textarea  name="company_address" id ="company_address" class="form-control" required data-validation-required-message="This field is required">{{ $company->company_address}}</textarea>
                                            
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Pincode <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_pincode" id ="company_pincode" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_pincode}}"> </div>
                                       
                                    </div>

                                    
                                    
                                    <div class="form-group">
                                        <h5>Select Industry <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="industry_id" required>
                                            @foreach($industry as $br)
                                            
                                                @if($br->industry_id == $company->industry_id )
                                                     <option value="{{$br->industry_id}}" selected >{{$br->industry_name}}</option>
                                                @else
                                                     <option value="{{$br->industry_id}}">{{$br->industry_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>

                                    <div class="form-group">
                                        <h5>Select segment <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="segment_id"  required>
                                                @foreach($segment as $br)
                                            
                                                @if($br->segment_id == $company->segment_id )
                                                     <option value="{{$br->segment_id}}" selected >{{$br->segment_name}}</option>
                                                @else
                                                     <option value="{{$br->segment_id}}">{{$br->segment_name}}</option>
                                                @endif

                                            @endforeach
                                           
                                        </select>    
                                        </div>
                                    </div>


                                
                              <div class="form-group">
                                        <h5>Select Head Office <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="company_ho"  required>
                                                @foreach($HeadOffice as $br)
                                            
                                                @if($br->head_office_id == $company->head_office_id)
                                                     <option value="{{$br->head_office_id}}" selected >{{$br->head_office_name}}</option>
                                                @else
                                                     <option value="{{$br->head_office_id}}">{{$br->head_office_name}}</option>
                                                @endif

                                            @endforeach
                                           
                                        </select>    
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <h5>Company Code <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_code" id ="company_code" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_code}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Contact Person <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="contact_person" id ="contact_person" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->contact_person}}"> </div>
                                       
                                    </div>

                                   <div class="form-group">
                                        <h5>Program type <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="program_type" id ="program_type" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->program_type}}"> </div>
                                       
                                    </div> 
                                    
                                    
                                    



                                    <div class="box-footer">
                                    <div class="col-sm-3 control-label"></div>
                                        <div class="col-sm-8">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-default" type="reset">Reset</button>
                                        </div>
                                    </div><!-- /.box-footer -->
                                </form>
                                </div>
                                </div>
                            </div>
                        </div>
Activity icon

Replied to How To Update Data From Multiple Table From One View.

updated code.

editcompany.blade.php

<div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Edit Company</h4>
                                <h6 class="card-subtitle"></h6>
                                @if ($errors->any())
                                <div class="alert alert-danger">
                                    <ul>
                                        @foreach ($errors->all() as $error)
                                            <li>{{ $error }}</li>
                                        @endforeach
                                    </ul>
                                </div>
                            @endif
                               <form method="post" action="{{url('/')}}/company/{{$company->company_id}}">
                                {{method_field('PATCH')}}{{csrf_field()}}
                               
                                     <div class="form-group">
                                        <h5>Company Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_name" id ="company_name" class="form-control" value="{{ $company->company_name}}" required data-validation-required-message="This field is required"> </div>
                                       
                                    </div>

                                    
                                    <div class="form-group">
                                        <h5>Company Email <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_email" id ="company_email" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_email}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Company mobile <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_mobile" id ="company_mobile" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_mobile}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Select State <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="company_state" id="company_state" onchange="getCity(this.value)" required>
                                                     <option>--Select State--</option>
                                             @foreach($state as $br)
                                            
                                                @if($br->state_id == $company->company_state )
                                                     <option value="{{$br->state_id}}" selected >{{$br->state_name}}</option>
                                                @else
                                                     <option value="{{$br->state_id}}">{{$br->state_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Select City <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="company_city" id="company_city" required>
                                                @foreach($city as $br)
                                            
                                                @if($br->city_id == $company->company_city )
                                                     <option value="{{$br->city_id}}" selected >{{$br->city_name}}</option>
                                                @else
                                                     <option value="{{$br->city_id}}">{{$br->city_name}}</option>
                                                @endif

                                            @endforeach
                                            
                                        </select>

                                        </div>
                                       
                                    </div>
                                     <div class="form-group">
                                        <h5>Company Address <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <textarea  name="company_address" id ="company_address" class="form-control" required data-validation-required-message="This field is required">{{ $company->company_address}}</textarea>
                                            
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Pincode <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_pincode" id ="company_pincode" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_pincode}}"> </div>
                                       
                                    </div>

                                    
                                    
                                    <div class="form-group">
                                        <h5>Select Industry <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="industry_id" required>
                                            @foreach($industry as $br)
                                            
                                                @if($br->industry_id == $company->industry_id )
                                                     <option value="{{$br->industry_id}}" selected >{{$br->industry_name}}</option>
                                                @else
                                                     <option value="{{$br->industry_id}}">{{$br->industry_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>

                                    <div class="form-group">
                                        <h5>Select segment <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="segment_id"  required>
                                                @foreach($segment as $br)
                                            
                                                @if($br->segment_id == $company->segment_id )
                                                     <option value="{{$br->segment_id}}" selected >{{$br->segment_name}}</option>
                                                @else
                                                     <option value="{{$br->segment_id}}">{{$br->segment_name}}</option>
                                                @endif

                                            @endforeach
                                           
                                        </select>    
                                        </div>
                                    </div>


                                
                              <div class="form-group">
                                        <h5>Select Head Office <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="company_ho"  required>
                                                @foreach($HeadOffice as $br)
                                            
                                                @if($br->head_office_id == $company->head_office_id)
                                                     <option value="{{$br->head_office_id}}" selected >{{$br->head_office_name}}</option>
                                                @else
                                                     <option value="{{$br->head_office_id}}">{{$br->head_office_name}}</option>
                                                @endif

                                            @endforeach
                                           
                                        </select>    
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <h5>Company Code <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="company_code" id ="company_code" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->company_code}}"> </div>
                                       
                                    </div>
                                    <div class="form-group">
                                        <h5>Contact Person <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="contact_person" id ="contact_person" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->contact_person}}"> </div>
                                       
                                    </div>

                                <div class="form-group">
                                        <h5>Program type <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="program_type" id ="program_type" class="form-control" required data-validation-required-message="This field is required" value="{{ $company->program_type}}"> </div>
                                       
                                    </div> 
                                    
                                    
                                    



                                    <div class="box-footer">
                                    <div class="col-sm-3 control-label"></div>
                                        <div class="col-sm-8">
                                        <button type="submit" class="btn btn-primary">Submit</button>
                                        &nbsp;&nbsp;
                                        <button class="btn btn-default" type="reset">Reset</button>
                                        </div>
                                    </div><!-- /.box-footer -->
                                </form>
                                </div>
                                </div>
                            </div>
                        </div>

Company.php

<?php

namespace App;


use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    protected $fillable =['company_name','industry_id','company_mobile','company_email','company_address','company_photo','username','password','company_state','company_city','company_country','company_pincode','company_code','login_first','segment_id','contact_person','company_currency','company_ifsc','company_acc_no','company_bank','company_pan','company_gst','company_cin','company_HO','program_tag_line','program_title','program_type'];
    protected $primaryKey = 'company_id';


public function CompanyOtherInfo(){
    return $this->hasOne(CompanyOtherInfo::class);
}

}

CompanyController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Industry;
use App\Segment;
use App\Company;
use App\City;
use App\Country;
use App\State;
use App\HeadOffice;
use App\CompanyOtherInfo;
use File;



class CompanyController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {
        $industry=Industry::get();
        //$country=Country::where('name','India')->first();
        $country=Country::get();
        $state=State::get();
        $city=city::get();
        $HeadOffice=HeadOffice::get();
        //dd($state);
        return view('backend.company.addCompany',compact('industry','state','country','city','HeadOffice'));
    }

    public function store(Request $request)
    {
        //dd(request()->all());
         $this->validate($request,[
                                'company_name'=>'unique:companies|required',
                               
                                ]);

         if($request->hasFile('company_photo')){
            

            $file = $request->file('company_photo');

            $destinationPath = public_path().'/company_photo/';
            $filename = $file->getClientOriginalName();
            if(!File::exists($destinationPath))
             {
                File::makeDirectory($destinationPath, $mode = 0777, true);
                $file->move($destinationPath, $filename);
             }
             else
             {
                $file->move($destinationPath, $filename);
             }
            

         //   echo  $filename;exit;
            }


            $company_id=Company::create([
            'industry_id' => request('industry_id'),
            'company_name' => request('company_name'),
            'company_email' => request('company_email'),
            'company_mobile' => request('company_mobile'),
            'company_state' => request('company_state'),
            'company_city' => request('company_city'),
            'company_pincode' => request('company_pincode'),
            'company_country' => request('company_country'),
            'company_address' => request('company_address'),
            'segment_id' => request('segment_id'),
            'company_photo' => $filename,
            'company_code' => request('company_code'),
            'contact_person'=>request('contact_person'),
            'username' => request('username'),
            'password' => request('password'),
            'login_first' => 0,

            ]);
              
         // dd($company_id);

            if($company_id->company_id!=null)
            {
                //dd('hi');
                CompanyOtherInfo::create([
            'company_currency' => request('company_currency'),
            'company_ifsc' => request('company_ifsc'),
            'company_acc_no' => request('company_acc_no'),
            'company_bank' => request('company_bank'),
            'company_pan' => request('company_pan'),
            'company_gst' => request('company_gst'),
            'company_cin' => request('company_cin'),
            'program_tag_line' => request('program_tag_line'),
            'program_title' => request('program_title'),
            'program_type' => request('program_type'),
            'company_ho' => request('company_ho'),
            'company_id' => $company_id->company_id
                
            ]);


        }

                
        return redirect('company/view');
    }

    public function show()
    {
        $company=Company::join('industries','companies.industry_id','=','industries.industry_id')
                        ->join('segments','companies.segment_id','=','segments.segment_id')->get();
        
        
        $industry=Industry::get();
        $segment=Segment::get();
        //return $names;
        return view('backend.company.viewCompany',compact('company', 'industry','segment'));
    }

    public function companyAjax($industry)
    {
        $company = Company::where("industry_id",$industry)
                    ->pluck('companies.company_name','companies.company_id')->all();
        return json_encode($company);
    }

    public function edit($company_id)
    {
        //dd($company);

        $company=company::findOrFail($company_id);
        $industry=Industry::get();
        $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city=City::where('state_id',$company->company_state)->get();
        $segment=Segment::get();
        $HeadOffice=HeadOffice::get();
        $CompanyOtherInfo=CompanyOtherInfo::get();

      

        //dd($industry);
        //dd($HeadOffice);
        //dd($program_type);
        return view('backend.company.editCompany',compact('company','industry','state','city','segment','HeadOffice','CompanyOtherInfo'));
    }

    public function update(Request $request, Company $company) 
    {
       $company->update($request->all());
       $company->companyOtherInfo->update($request->all());
        
    return redirect('company/view');

    }
   
   public function destroy(Company $company)
    {
        $company->delete();
        return redirect('company/view');
    }
}