Kanchan186

Kanchan186

Software Engineer at Pune

Member Since 4 Months Ago

Pune,Maharashtra

Experience Points
8,170
Total
Experience

1,830 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
8,170 XP
Dec
09
5 hours ago
Activity icon

Replied to Problem With Editing Dropdown Values , Please Check My Code Where I Going Wrong

@design-studio yes sir, but what should i do? to resolve this problem

Activity icon

Replied to ErrorException (E_WARNING) Invalid Argument Supplied For Foreach()

@tykus can u please more explain about-@method('patch')

actually i cant understand where i need to update my code

Activity icon

Replied to ErrorException (E_WARNING) Invalid Argument Supplied For Foreach()

sorry actually i used this

//edit Mechanic Brands
Route::get('mechanic_brands/{mech_brand_id}/edit','[email protected]');

Route::patch('mechanic_brands/{mech_brand_id}','[email protected]');

still it calls store function

Activity icon

Started a new Conversation ErrorException (E_WARNING) Invalid Argument Supplied For Foreach()

error is occurred because it calls store function instead of update function, cant understand why it happens.

link to edit

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

web.php

//add Mechanic Brands
Route::get('mechanic_brands/{mechanic_id}/Add','[email protected]');
//save Mechanic_Brands
Route::post('mechanic_brands/{mechanic_id}','[email protected]');

//edit Mechanic Brands
Route::get('mechanic_brands/{mech_brand_id}/edit','[email protected]');

Route::post('mechanic_brands/{mech_brand_id}','[email protected]');

//delete Mechanic Brands
Route::get('mechanic_brands/{mech_brand}','[email protected]');
//get segment wise brand using ajax
Route::get('brand/Ajax/{segment}','[email protected]');

edit view

 <form method="post" action="{{url('/')}}/mechanic_brands/{{$mech_brand->mech_brand_id}}" enctype="multipart/form-data" novalidate>
                                    {{csrf_field()}}

                                
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Segment Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="segment_id" required data-validation-required-message="This field is required" onchange="getBrand(this.value)" >
                                            @foreach($segment as $br)
                                            
                                                @if($br->segment_id == $mech_brand->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">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Brand Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="brand_id" required data-validation-required-message="This field is required">
                                            @foreach($brand as $br)
                                            
                                                @if($br->brand_id == $mech_brand->brand_id )
                                                     <option value="{{$br->brand_id}}" selected >{{$br->brand_name}}</option>
                                                @else
                                                     <option value="{{$br->brand_id}}">{{$br->brand_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>
                              
                                               
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

controller


public function edit(MechBrand $mech_brand_id)
  {
    //dd('hi');
    //dd($mech_brand_id);
    $mech_brand=MechBrand::where('mech_brands.mech_brand_id',$mech_brand_id->mech_brand_id)
              
              ->join('segments','mech_brands.segment_id','=','segments.segment_id')
              ->join('brands','mech_brands.brand_id','=','brands.brand_id')
              
              ->select('segment_name','brand_name', 'mech_brands.*')->first();
   
    $brand=Brands::get();
    $segment=Segment::get();
    
    //dd($statearea);
    return view('backend.mechanic_brands.editMechBrands',compact('mech_brand','segment','brand'));
  }


 public function update(Request $req,MechBrand $mech_brand_id)
  {
   // dd($mech_brand_id);
    //dd($req->all());

    $mechanic_id=request('mechanic_id');
    $segment_id=request('segment_id');
    $brand_id=request('brand_id');
        
    
    $mech_brand_id->update($req->all());

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

Started a new Conversation Problem With Editing Dropdown Values , Please Check My Code Where I Going Wrong

problem is:

stored head office with name ''Pune Head office" on pune city.

when i click on edit, it shows "Nashik head office" but i am not stored nashik headofice.

Then i again select city Pune it shows only Pune's Head Office means javascript runs properly.

but i cant understand why it shows nashik head office on edit page.

My code:

edit view

 <div class="form-group">
                                        <h5>Select Country <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="dist_company_country" id="dist_company_country" onchange="getState(this.value)" required>
                                                     <option>--Select country--</option>
                                             @foreach($country as $br)
                                            
                                                @if($br->country_id == $distributor->dist_company_country )
                                                     <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">
                                        <h5>Select State <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="dist_company_state" id="dist_company_state" onchange="getCity(this.value)" required>
                                                     <option>--Select State--</option>
                                             @foreach($state as $br)
                                            
                                                @if($br->state_id == $distributor->dist_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="dist_company_city" id="dist_company_city" onchange="getHo(this.value)" required>
                                                @foreach($city as $br)
                                            
                                                @if($br->city_id == $distributor->dist_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>Select Distributor Head Office <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control"  name="dist_company_ho"   required>
                                                @foreach($HeadOffice as $br)
                                            
                                                @if($br->head_office_id == $DistributorOtherInfos->dist_company_ho)
                                                     <option value="{{$br->head_office_id}}" selected >{{$br->head_office_name}}</option>
                                                @else
                                                     <option value="{{$br->head_office_id}}" selected >{{$br->head_office_name}}</option>
                                                @endif

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

script

 <script type="text/javascript">
                        function getState(country)
                            {
                               if(country) {
                                        $.ajax({
                                            url: '{{url('/')}}/state/ajax/'+country,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {

                                             // alert(data);
                                             console.log(data)
                                        
                                                $('select[name="dist_company_state"]').empty();
                                                $('select[name="dist_company_state"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="dist_company_state"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="dist_company_state"]').empty();
                                    }
                            }
                        
                         function getCity(state)
                            {
                               if(state) {
                                        $.ajax({
                                            url: '{{url('/')}}/city/ajax/'+state,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                                 console.log(data)

                                                $('select[name="dist_company_city"]').empty();
                                                $('select[name="dist_company_city"]').prepend('<option value="">--Select City--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="dist_company_city"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="dist_company_city"]').empty();
                                    }
                            }



                           function getHo(city)
                            {
                               if(city) {
                                        $.ajax({
                                            url: '{{url('/')}}/head_office/ajax/'+city,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                        
                                         console.log(data)
                                                $('select[name="dist_company_ho"]').empty();
                                                $('select[name="dist_company_ho"]').prepend('<option value="">--Select Head Office--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="dist_company_ho"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="dist_company_ho"]').empty();
                                    }
                            }



                    </script>

controller

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

        $distributor=distributor::findOrFail($distributor_id);
        $HeadOffice=HeadOffice::get();

        $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city=City::where('state_id',$distributor->dist_company_state)->get();
        $country=country::get();
        
        $DistributorOtherInfos=DistributorOtherInfos::where('distributor_other_infos.distributor_id',$distributor_id)->first();

        //dd($industry);
        //dd($HeadOffice);
        //dd($program_type);
        return view('backend.distributor.editDistributor',compact('distributor','country','state','city','HeadOffice','DistributorOtherInfos'));
    }

 public function stateAjax($country)
    {
        $state = state::where("country_id",$country)
                    ->pluck('states.state_name','states.state_id')->all();
        return json_encode($state);
    }

    public function cityAjax($state)
    {
        $city = City::where("state_id",$state)
                    ->pluck('cities.city_name','cities.city_id')->all();
        return json_encode($city);
    }
   
   public function HeadofficeAjax($city)
    {
        $HeadOffice = HeadOffice::where("city_id",$city)
                    ->pluck('head_offices.head_office_name','head_offices.head_office_id')->all();
        return json_encode($HeadOffice);
    }


web.php

Route::get('state/ajax/{country}','[email protected]');
Route::get('city/ajax/{state}','DistributorCont[email protected]');
Route::get('head_office/ajax/{city}','[email protected]');
Activity icon

Awarded Best Reply on ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov finally i found my mistake

i updated my code and it works

public function edit(MechBrand $mech_brand_id)
  {
    //dd('hi');
    //dd($mech_brand_id);
    $mech_brand=MechBrand::where('mech_brands.mech_brand_id',$mech_brand_id->mech_brand_id)
              
              ->join('segments','mech_brands.segment_id','=','segments.segment_id')
              ->join('brands','mech_brands.brand_id','=','brands.brand_id')
              
              ->select('segment_name','brand_name', 'mech_brands.*')->first();
   
    $brand=Brands::get();
    $segment=Segment::get();
    
    //dd($statearea);
    return view('backend.mechanic_brands.editMechBrands',compact('mech_brand','segment','brand'));
  }

thanks for the help

Activity icon

Replied to ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov finally i found my mistake

i updated my code and it works

public function edit(MechBrand $mech_brand_id)
  {
    //dd('hi');
    //dd($mech_brand_id);
    $mech_brand=MechBrand::where('mech_brands.mech_brand_id',$mech_brand_id->mech_brand_id)
              
              ->join('segments','mech_brands.segment_id','=','segments.segment_id')
              ->join('brands','mech_brands.brand_id','=','brands.brand_id')
              
              ->select('segment_name','brand_name', 'mech_brands.*')->first();
   
    $brand=Brands::get();
    $segment=Segment::get();
    
    //dd($statearea);
    return view('backend.mechanic_brands.editMechBrands',compact('mech_brand','segment','brand'));
  }

thanks for the help

Dec
06
3 days ago
Activity icon

Replied to ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov sorry sir but still same error occurred

Property [mech_brand_id] does not exist on this collection instance.
Activity icon

Replied to ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov

i used this

$mech_brand=MechBrand::findOrFail($mech_brand_id);

so i commented that.

still same error

Property [mech_brand_id] does not exist on this collection instance. (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)```
Activity icon

Replied to ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov now i updated my code

MechanicView

<table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                     <tbody>
                        
                        
                        <tr>
                        <td><h6>Segment</h6></td>
                        <td><h6>Brands</h6></td>
                        <td><h6>Operations</h6></td>
                        </tr>

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

                        <tr>
                        <td><h6>{{ $br->segment_name}}</h6></td>    
                        <td><h6>{{ $br->brand_name}}</h6></td> 

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

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


                        </td>     
                        </tr>
                         @endforeach

                       </tbody>
                   </table>

web.php

/edit Mechanic Brands
Route::get('mechanic_brands/{mech_brand_id}/edit','[email protected]');

Route::patch('mechanic_brands/{mech_brand_id}','[email protected]');

controller

public function edit(MechBrand $mech_brand_id)
  {
    //dd($mech_brand_id);
    $mech_brand=MechBrand::findOrFail($mech_brand_id);
    // $mech_brand=MechBrand::find(1);
    $segment=Segment::get();
    $brand=Brands::get();
    $mechanic=Mechanic::get();
    //$mech_brand=MechBrand::get();
   
   return view('backend.mechanic_brands.editMechBrands',compact('mechanic','brand','segment','mech_brand'));
  }

Editview

<form method="post" action="{{url('/')}}/mechanic_brands/{{$mech_brand->mech_brand_id}}" enctype="multipart/form-data" novalidate>
                                    {{csrf_field()}}

                                
                                    <div class="form-group">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Segment Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="segment_id" required data-validation-required-message="This field is required">
                                            @foreach($segment as $br)
                                            
                                                @if($br->segment_id == $mech_brand->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">
                                        <label for="inputPassword3" class="col-sm-3 control-label">Brand Name 
                                        <span class="required"> * </span></label>
                                        <div class="col-sm-8">
                                        <select class="form-control" name="brand_id" required data-validation-required-message="This field is required">
                                            @foreach($brand as $br)
                                            
                                                @if($br->brand_id == $mech_brand->brand_id )
                                                     <option value="{{$br->brand_id}}" selected >{{$br->brand_name}}</option>
                                                @else
                                                     <option value="{{$br->brand_id}}">{{$br->brand_name}}</option>
                                                @endif

                                            @endforeach
                                        </select>
                                        </div>
                                    </div>
                              
                                               
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

still getting same error. please check where i going wrong?

Activity icon

Replied to ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

@nakov now it shows error

ErrorException (E_ERROR)
Property [mech_brand_id] does not exist on this collection instance. (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

Activity icon

Started a new Conversation ErrorException (E_ERROR) Undefined Variable: Mech_brand (View: C:\xampp\htdocs\partsanalysis\resources\views\backend\mechanic_brands\editMechBrands.blade.php)

edit link

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

view(editMechBrands)

<form method="post" action="{{url('/')}}/mechanic_brands/{{$mech_brand->mech_brand_id}}" enctype="multipart/form-data" novalidate>
                                    {{csrf_field()}}

controller

public function edit(MechBrand $mech_brand)
  {
    $segment=Segment::get();
    $brand=Brands::get();
    $mechanic=Mechanic::get();
     $mech_brand=MechBrand::get();

   return view('backend.mechanic_brands.editMechBrands',compact('mechanic','brand','segment'));
  }

web.php


Route::get('mechanic_brands/{mech_brand}/edit','[email protected]');
Route::patch('mechanic_brands/{mech_brand}','[email protected]');
Dec
04
5 days ago
Activity icon

Replied to ErrorException (E_NOTICE) Undefined Variable: Filename

@sinnbeck sir

i already use this in my code


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

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

            $destinationPath = public_path().'/brand_logos/';
            $filename = $file->getClientOriginalName();
Activity icon

Started a new Conversation ErrorException (E_NOTICE) Undefined Variable: Filename

view

 <form class="m-t-40" method="post" action="{{url('/')}}/brand" enctype="multipart/form-data" novalidate>
                                    {{csrf_field()}}
                                    

                                    
                                    <div class="form-group">
                                                <h5>Industry Name <span class="text-danger">*</span></h5>
                                                <div class="controls">
                                                    <select name="industry_id" class="form-control" onchange="getSegment(this.value)"  required data-validation-required-message="This field is required">
                                            
                                            <option value="">--Select Industry--</option>
                                           
                                            @foreach($industry as $br)
                                            <option value="{{$br->industry_id}}">{{$br->industry_name}}</option>
                                            @endforeach

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




                                      <div class="form-group">
                                        <h5>Segment Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <select class="form-control" name="segment_id" id="segment_id" required data-validation-required-message="This field is required">
                                                <option>--Select Segment--</option>
                                           
                                        </select> </div>
                                       
                                    </div>

                                    <div class="form-group">
                                        <h5>Brand Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="brand_name" id ="brand_name" class="form-control" required data-validation-required-message="This field is required"> </div>
                                       
                                    </div>

                                    <div class="form-group">
                                        <h5>Brand Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="file" name="brand_logo" id ="brand_logo" class="form-control" required data-validation-required-message="This field is required"> </div>
                                       
                                    </div>

                                    


                                    
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Industry;
use App\Segment;
use App\Brands;
use File;

class BrandsController extends Controller
{
     public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {
        $industry=Industry::get();
        $segment=Segment::get();
        $brand=Brands::get();
        return view('backend.brand.addBrand',compact('industry'));
    }

    public function store(Request $request)
    {
        //dd(request()->all());
         


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

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

            $destinationPath = public_path().'/brand_logos/';
            $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
        $brand_id=Brands::create([
        'industry_id' => request('industry_id'),
        'segment_id' => request('segment_id'),
        'brand_name' => request('brand_name'),
        'brand_logo' => $filename,
        ]);
        
        
        return redirect('brand/view');
    }

    public function show()
    {
        $brand=Brands::join('industries','brands.industry_id','=','industries.industry_id')
                    ->join('segments','brands.segment_id','=','segments.segment_id')
                    ->get();
        $industry=Industry::get();
        //return $names;
        return view('backend.brand.viewBrand',compact('brand', 'industry'));
    }

    public function brandAjax($industry)
    {
        $brand = Brands::where("industry_id",$industry)
                    ->pluck('brand.brand_name','brand.brand_id')->all();
        return json_encode($brand);
    }

    public function edit(Brands $brand)
    {
        //dd($brand);
        $industry=Industry::get();
        $segment=Segment::get();
        //dd($industry);
        return view('backend.brand.editBrand',compact('brand','industry','segment'));
    }

    public function update(Request $req,Brands $brand)
    {

        if($req->hasFile('brand_logo')){
            
            $files=public_path().'/brand_logos/'.$req->input('brand_logo1');
            File::delete($files);
            //dd($files);
            $file = $req->file('brand_logo');

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

            
           // echo  $filename;
            }
            else{
                $filename=$req->input('brand_logo1');
            }
        $brand->update([
        'industry_id' => request('industry_id'),
        'segment_id' => request('segment_id'),
        'brand_name' => request('brand_name'),
        'brand_logo' => $filename,
        ]);


        return redirect('brand/view');

    }
   
   public function destroy(Brands $brand)
    {
        $files=public_path().'/brand_logos/'.$brand->brand_logo;
            File::delete($files);
        $brand->delete();
        return redirect('brand/view');
    }
}
Dec
03
6 days ago
Activity icon

Started a new Conversation Illuminate \ Database \ QueryException (42S22) SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'distributor_other_infos.dist.dist_company_ho' In 'on Clause' (SQL: Select * From `distributor_other_infos` Inner Join `head_offices` On `distributor_oth

view(EditDistributor_HeadOffice)

 <div class="form-group">
                                        <h5>Select Distributor Head Office <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control"  name="dist_company_ho"   required>
                                                @foreach($HeadOffice as $br)
                                            
                                                @if($br->head_office_id == $HeadOffice->dist_company_ho )
                                                     <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>

controller(EDIT function)

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

        $distributor=distributor::findOrFail($distributor_id);
        $HeadOffice=HeadOffice::get();

        $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city=City::where('state_id',$distributor->dist_company_state)->get();
        $country=country::get();
        
        
        //$CompanyOtherInfo=CompanyOtherInfo::get();

       // $company=company::where('companies.company_id',$company_id)->get();

        $DistributorOtherInfos=DistributorOtherInfos::where('distributor_other_infos.distributor_id',$distributor_id)
       ->join('head_offices','distributor_other_infos.dist.dist_company_ho','=','head_offices.head_office_id') 
        ->first();

        //dd($industry);
        //dd($HeadOffice);
        //dd($program_type);
        return view('backend.distributor.editDistributor',compact('distributor','country','state','city','HeadOffice','DistributorOtherInfos'));
    }
Dec
02
1 week ago
Activity icon

Started a new Conversation Illuminate \ Database \ QueryException (42S22) SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Region_areas.country_id' In 'on Clause' (SQL: Select * From `region_areas` Inner Join `countries` On ` Region_areas`.`country_id` = `countries`.`countr

controlller

public function edit(Region $region)
    {
        //dd($region);
        $country=Country::get();
        $regionarea=RegionArea::join('countries',' region_areas.country_id','=','countries.country_id')->get();
        $region=Region::get();

        $zone=Zone::get();
        //dd($zone);
        return view('backend.region.editRegion',compact('country','region','zone','regionarea'));
    }

view

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


                            <div class="form-group">
                                        <h5>Select Country <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="country_id" id="country_id" onchange="getZone(this.value)" required>
                                                     <option>--Select Country--</option>
                                             @foreach($country as $br)
                                            
                                                @if($br->country_id == $regionarea->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 == $region->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="{{ $region->region_name}}"required>
                                        </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>
Nov
29
1 week ago
Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

             <div class="form-group">
                                        <h5>Region Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="region_id" onchange="getState(this.value)" required>
                                                <option>--Select Region--</option>
                                           
                                        </select>
                                    </div>
                                       
                                    </div>
                                       
                                    
                                    <div class="form-group">
                                        <h5>Select State <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="state_id" id="state_id" onchange="getCity(this.value)"   required>
                                            <option>--Select State--</option> 
                                           
                                        </select>

                                        </div>
                                       
                                    </div>

@nakov please check this code

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov still it shows null... may be problem in my view please check my view for region and state

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov sir rarea_id is not required i think because i have to fetch states info on region_id

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov

using above code in network tab

and in console

{1: "Zone 1", 3: "zone 2"}
{15: "South India"}
[]
Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov Do you have protected $table = 'region_areas'; in your State model?

         no sir
Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov in console

{1: "Zone 1", 3: "zone 2"}
{15: "South India"}
 []

gives output this type state value is null []

in network tab output

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@nakov first code is wrong i realize my mistake , i am trying to fetch data from region table where state_id is not present.

and i updated my code please check updated code actually i want to fetch data from region_areas table and i made changes for that

still it gets null value

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@jonhcr i updated my code

i want to fetch values from region_areas table

in controller

 public function StateAjax($region_area)
    {
        $state = State::where("region_id",$region_area)
                    ->pluck('states.state_id','states.state_id')->all();
        return json_encode($state);
    }

in script

function getState(region_area)
                            {
                               if(region_area) {
                                        $.ajax({
                                            url: '{{url('/')}}/state/ajax/'+region_area,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                        
                                             console.log(data);
                                                $('select[name="state_id"]').empty();
                                                $('select[name="state_id"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="state_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="state_id"]').empty();
                                    }
                            }

in web.php

Route::get('state/ajax/{region_area}','[email protected]');

please check my code

Activity icon

Replied to Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

@jonhcr in network bar all request status is 200 means ok

Activity icon

Started a new Conversation Console.log(data) Shows Null Value Please Check My Code. Why It Shows Null Value?

view

 <form class="m-t-40" method="post" action="area" enctype="multipart/form-data">
                                    {{csrf_field()}}


                                  <div class="form-group">
                                        <h5>Select Country <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="company_country" id="company_country" onchange="getZone(this.value)" required>
                                                     <option>--Select country--</option>
                                             @foreach($country as $st)
                                                     <option value="{{$st->country_id}}">{{$st->country_name}}</option>
                                             @endforeach
                                        </select>

                                        </div>
                                       
                                    </div>

                                  


                                    <div class="form-group">
                                        <h5>Zone Name<span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="zone_id" onchange="getRegion(this.value)" required>
                                                <option>--Select Zone--</option>
                                            
                                        </select>

                                        </div>
                                       
                                    </div>

                                    <div class="form-group">
                                        <h5>Region Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control " name="region_id" onchange="getState(this.value)" required>
                                                <option>--Select Region--</option>
                                           
                                        </select>


                                         

                                        </div>
                                       
                                    </div>
                                       
                                    
                                    <div class="form-group">
                                        <h5>Select State <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                             <select class="form-control" name="state_id" id="state_id"  required>
                                            <option>--Select State--</option>    
                                                     
                                        </select>

                                        </div>
                                       
                                    </div>


                                <div class="form-group">
                                        <h5>Area Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="area_name" id ="area_name" class="form-control" required data-validation-required-message="This field is required" required> </div>
                                        </div>




                                    <div class="form-group">
                                        <h5>Select State Area <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <select class="select2 m-b-10 select2-multiple" name="state_area[]" id="state_area" style="width: 100%" multiple="multiple" data-placeholder="Choose" required data-validation-required-message="Please select state area" required>
                                    
                                    @foreach($city as $ct)
                                    <option value="{{$ct->city_id}}">{{$ct->city_name}}</option>
                                    @endforeach
                                        
                                   
                                </select>
                                           

                                        </div>
                                       
                                    </div>
                                    

                                    
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

script

 function getZone(country)
                            {
                               if(country) {
                                        $.ajax({
                                            url: '{{url('/')}}/zone/ajax/'+country,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                                 console.log(data)

                                                $('select[name="zone_id"]').empty();
                                                $('select[name="zone_id"]').prepend('<option value="">--Select Zone--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="zone_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="zone_id"]').empty();
                                    }
                            }
                                               




 
 function getRegion(zone)
                            {
                               if(zone) {
                                        $.ajax({
                                            url: '{{url('/')}}/region/ajax/'+zone,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                        
                                             console.log(data);
                                                $('select[name="region_id"]').empty();
                                                $('select[name="region_id"]').prepend('<option value="">--Select Region--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="region_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="region_id"]').empty();
                                    }
                            }

 function getState(region)
                            {
                               if(region) {
                                        $.ajax({
                                            url: '{{url('/')}}/state/ajax/'+region,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                        
                                             console.log(data);
                                                $('select[name="state_id"]').empty();
                                                $('select[name="state_id"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="state_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="state_id"]').empty();
                                    }
                            }

controller

 public function ZoneAjax($country)
    {
        $zone = Zone::where("country_id",$country)
                    ->pluck('zones.zone_name','zones.zone_id')->all();
        return json_encode($zone);
    }

    public function RegionAjax($zone)
    {
        $region = Region::where("zone_id",$zone)
                    ->pluck('regions.region_name','regions.region_id')->all();
        return json_encode($region);
    }

    public function StateAjax($region)
    {
        $state = State::where("region_id",$region)
                    ->pluck('states.state_name','states.state_id')->all();
        return json_encode($state);
    }

web.php

Route::get('zone/ajax/{country}','[email protected]');

Route::get('region/ajax/{zone}','[email protected]');

Route::get('state/ajax/{region}','[email protected]');


this gives null value

http://localhost/partsanalysis/public/state/ajax/16
Nov
26
1 week ago
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

@tisuchi

using above code

getting error

Illuminate \ Database \ QueryException (42S22)
SQLSTATE[42S22]: Column not found: 1054 Unknown column ' head_offices.HO_country' in 'on clause' (SQL: select * from `head_offices` inner join `countries` on ` head_offices`.`HO_country` = `countries`.`country_id` inner join `states` on ` head_offices`.`HO_state` = `states`.`state_id` inner join `cities` on ` head_offices`.`HO_city` = `cities`.`city_id`)
Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

@tisuchi

public function show()
    {

    $HeadOffice=HeadOffice::join('countries',' head_offices.HO_country','=','countries.country_id')
                            ->join('states',' head_offices.HO_state','=','states.state_id')
                            ->join('cities',' head_offices.HO_city','=','cities.city_id')
                            ->get(); 

        $HeadOffice=HeadOffice::get();
        $country=Country::get();
        $state=State::get();
        $city=city::get();
                //return $names;
        return view('backend.head_office.viewHeadOffice',compact('country','state','city','HeadOffice'));
    }

i used that but same error occurs

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

@tisuchi

how to fetch country_name from head_offices table to display on webpage

 @foreach($HeadOffice as $hd)

                                            <tr>
                                                <td>{{$i++}}</td>
                                                <td>{{$hd->country_name}}</td>
                                                <td>{{$hd->state_name}}</td>
                                                <td>{{$hd->city_name}}</td>
                                                <td>{{$hd->head_office_name}}</td>
 @endforeach
                                               

for that what i need to write in show function in controller

Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'city_id' In 'where Clause' (SQL: Select `head_offices`.`head_office_name`, `head_offices`.`head_office_id` From `head_offices` Where `city_id` = 317)

view

  <div class="form-group">
            <h5>Select Country <span class="text-danger">*</span></h5>
            <div class="controls">
                                            
                <select class="form-control" name="company_country" id="company_country" onchange="getState(this.value)" required>
                <option>--Select country--</option>
                @foreach($country as $br)
                <option value="{{$br->country_id}}">{{$br->country_name}}</option>
                 @endforeach
                </select>
            </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>
                      
                </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" onchange="getHo(this.value)" required>
               <option>--Select City--</option>
               
               </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" id="company_ho" required>
            <option>--Select Head Office--</option>

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

script

 <script type="text/javascript">
                        function getState(country)
                            {
                               if(country) {
                                        $.ajax({
                                            url: '{{url('/')}}/state/ajax/'+country,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {

                                             // alert(data);
                                             console.log(data)
                                        
                                                $('select[name="company_state"]').empty();
                                                $('select[name="company_state"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="company_state"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="company_city"]').empty();
                                    }
                            }
                        
                         function getCity(state)
                            {
                               if(state) {
                                        $.ajax({
                                            url: '{{url('/')}}/city/ajax/'+state,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                                 console.log(data)

                                                $('select[name="company_city"]').empty();
                                                $('select[name="company_city"]').prepend('<option value="">--Select City--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="company_city"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="company_city"]').empty();
                                    }
                            }



                            function getHo(city)
                            {
                               if(city) {
                                        $.ajax({
                                            url: '{{url('/')}}/head_office/ajax/'+city,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                        
                                         console.log(data)
                                                $('select[name="company_ho"]').empty();
                                                $('select[name="company_ho"]').prepend('<option value="">--Select Head Office--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="company_ho"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="company_ho"]').empty();
                                    }
                            }
</script>

Controller


     public function stateAjax($country)
    {
        $state = state::where("country_id",$country)
                    ->pluck('states.state_name','states.state_id')->all();
        return json_encode($state);
    }

    public function cityAjax($state)
    {
        $city = City::where("state_id",$state)
                    ->pluck('cities.city_name','cities.city_id')->all();
        return json_encode($city);
    }
   
   public function HeadofficeAjax($city)
    {
        $HeadOffice = HeadOffice::where("city_id",$city)
                    ->pluck('head_offices.head_office_name','head_offices.head_office_id')->all();
        return json_encode($HeadOffice);
    }

web.php

Route::get('state/ajax/{country}','[email protected]');
Route::get('city/ajax/{state}','[email protected]');
Route::get('head_office/ajax/{city}','[email protected]');

headoffice table

company table

company_other_info table

please tell me where i going wrong..?

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

 public function up()
    {
        Schema::create('employees', function (Blueprint $table) {
            $table->increments('emp_id');
            $table->string('emp_fname');
            $table->string('emp_lname');
            $table->date('emp_bdate');
            $table->string('gender');
            $table->integer('emp_mobile')->unique();
            $table->integer('emp_alt_mobile')->unique();
            $table->string('emp_email')->unique();
            $table->string('emp_address');
            $table->string('emp_photo');
            $table->string('emp_username');
            $table->string('password');
            $table->string('emp_state');
            $table->string('emp_city');
            $table->string('emp_country');
            $table->integer('emp_pincode');
            $table->string('emp_id_proof');
            $table->integer('login_first');
            $table->timestamps();
        });

this code works

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

<?php

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

class CreateHeadOfficesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('head_offices', function (Blueprint $table) {
            $table->increments('head_office_id');
            $table->string('HO_country');
            $table->string('HO_state');
            $table->string('HO_city');
            $table->string('head_office_name');
            $table->timestamps();
        });
    }

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

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

@sinnbeck

i updated my code like that

public function show()
    {

      $HeadOffice=HeadOffice::join('countries',' head_offices.HO_country','=','countries.country_id')
                            ->join('states',' head_offices.HO_state','=','states.state_id')
                            ->join('cities',' head_offices.HO_city','=','cities.city_id')
                            ->get();
        
                //return $names;
        return view('backend.head_office.viewHeadOffice',compact('HeadOffice'));
    }

still error

SQLSTATE[42S22]: Column not found: 1054 Unknown column ' head_offices.HO_country' in 'on clause' (SQL: select * from `head_offices` inner join `countries` on ` head_offices`.`HO_country` = `countries`.`country_id` inner join `states` on ` head_offices`.`HO_state` = `states`.`state_id` inner join `cities` on ` head_offices`.`HO_city` = `cities`.`city_id`)
Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column ' Head_offices.country_id' In 'on Clause' (SQL: Select * From `head_offices` Inner Join `countries` On ` Head_offices`.`country_id` = `countries`.`country_id` Inner Join `states` On ` Head_offices`.`s

controller

public function show()
    {

      $HeadOffice=HeadOffice::join('countries',' head_offices.country_id','=','countries.country_id')
                            ->join('states',' head_offices.state_id','=','states.state_id')
                            ->join('cities',' head_offices.city_id','=','cities.city_id')
                            ->get();
        
        
        $country=Country::get();
        $state=State::get();
        $city=city::get();

        //return $names;
        return view('backend.head_office.viewHeadOffice',compact('country','state','city','HeadOffice'));
    }

view

          <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>Country</th>
                                                <th>State</th>
                                                <th>City</th>
                                                <th>Head Office </th>
                                                <th>Operations</th>
                                            </tr>
                                        </thead>
                                       
                                        <tbody>

                                          <?php $i=1; ?>
                                          @foreach($HeadOffice as $hd)

                                            <tr>
                                                <td>{{$i++}}</td>
                                                <td>{{$hd->country_name}}</td>
                                                <td>{{$hd->state_name}}</td>
                                                <td>{{$hd->city_name}}</td>
                                                <td>{{$hd->head_office_name}}</td>
                                               
                                                <td>
                                                  <a href="{{url('/')}}/head_office/{{$hd->head_office_id}}/edit"><i class="fas fa-edit"></i></a>  
                                                  &nbsp;<a href="{{url('/')}}/head_office/{{$hd->head_office_id}}" onclick="return confirm('Do you want delete this record')"><i class="fas fa-trash" ></i>
                                                </td>
                                            </tr>

                                           @endforeach
                                            
                                        </tbody>
                                    </table>
                                </div>
Activity icon

Started a new Conversation Illuminate \ Database \ QueryException (HY000) SQLSTATE[HY000]: General Error: 1364 Field 'HO_country' Doesn't Have A Default Value (SQL: Insert Into `head_offices` (`head_office_name`, `updated_at`, `created_at`) Values (kkk, 2019-11-26 20:44:40, 2019-11

view

    <form class="m-t-40" method="post" action="head_office" novalidate>
                                    {{csrf_field()}}
                                    <div class="form-group">

                 <div class="form-group">
            <h5>Select Country <span class="text-danger">*</span></h5>
            <div class="controls">
                                            
                <select class="form-control" name="HO_country" id="HO_country" onchange="getState(this.value)" required>
                <option>--Select country--</option>
                @foreach($country as $br)
                <option value="{{$br->country_id}}">{{$br->country_name}}</option>
                 @endforeach
                </select>
            </div>
        </div>
                
        <div class="form-group">
            <h5>Select State <span class="text-danger">*</span></h5>
            <div class="controls">
                                            
                <select class="form-control" name="HO_state" id="HO_state" onchange="getCity(this.value)" required>
                <option>--Select State--</option>
                      
                </select>
            </div>
        </div>

       <div class="form-group">
            <h5>Select City <span class="text-danger">*</span></h5>
            <div class="controls">

               <select class="form-control" name="HO_city" id="HO_city" required>
               <option>--Select City--</option>
               
               </select>
           </div>
     </div>


 <h5>Head office Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="head_office_name" id ="head_office_name" class="form-control" required data-validation-required-message="This field is required"> </div>
                                        <div class="form-control-feedback"><small>Add <code>required</code> attribute to field for required validation.</small></div>
                                    </div>
                                    
                                            <div class="text-xs-right">
                                                <button type="submit" class="btn btn-info">Submit</button>
                                                <button type="reset" class="btn btn-inverse">Cancel</button>
                                            </div>
                                </form>

script

<script type="text/javascript">
                        function getState(country)
                            {
                               if(country) {
                                        $.ajax({
                                            url: '{{url('/')}}/state/ajax/'+country,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {

                                             // alert(data);
                                             console.log(data)
                                        
                                                $('select[name="HO_state"]').empty();
                                                $('select[name="HO_state"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="HO_state"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="HO_state"]').empty();
                                    }
                            }
                        
                         function getCity(state)
                            {
                               if(state) {
                                        $.ajax({
                                            url: '{{url('/')}}/city/ajax/'+state,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                                 console.log(data)

                                                $('select[name="HO_city"]').empty();
                                                $('select[name="HO_city"]').prepend('<option value="">--Select City--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="HO_city"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="HO_city"]').empty();
                                    }
                            }



                           

                           
                    </script>

controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\HeadOffice;
use App\City;
use App\Country;
use App\State;

class HeadOfficeController extends Controller
{
     public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {
        $country=Country::get();
        $state=State::get();
        $city=city::get();
        $HeadOffice=HeadOffice::get();

        return view('backend.head_office.addHeadOffice',compact('country','state','city','HeadOffice'));
    }

    public function store()
    {
        //dd(request()->all());

        
        $head_office_id=HeadOffice::create([
       
        'HO_country' => request('HO_country'),  
        'HO_state' => request('HO_state'),
        'HO_city' => request('HO_city'),
        'head_office_name' => request('head_office_name'),  
        ]);
        
        
        return redirect('head_office/view');
    }


public function cityAjax($state)
    {
        $city = City::where("state_id",$state)
                    ->pluck('cities.city_name','cities.city_id')->all();
        return json_encode($city);
    }

     public function stateAjax($country)
    {
        $state = state::where("country_id",$country)
                    ->pluck('states.state_name','states.state_id')->all();
        return json_encode($state);
    }


public function show()
    {
        $HeadOffice=HeadOffice::get();
        //return $names;
        return view('backend.head_office.viewHeadOffice',compact('HeadOffice'));
    }


public function edit($head_office_id)
    {
        $HeadOffice=HeadOffice::findOrFail($head_office_id);

        return view('backend.head_office.editHeadOffice',compact('HeadOffice'));
    }


    public function update(Request $req,HeadOffice $HeadOffice)
    {
            //dd($req->all());
        $HeadOffice->update($req->all());

        return redirect('head_office/view');

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



}
Nov
25
2 weeks ago
Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

@nakov finally i found my mistake

in web.php

i declared same url multiple times for different controllers

thanks for help.

my code works

Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

@nakov i have a separate controller for designation also may be it called from there also

DesignationController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Department;
use App\Designation;
class DesignationController extends Controller
{
     public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {
        $department=Department::get();
        return view('backend.designation.addDesignation',compact('department'));
    }

    public function store(Request $request)
    {
        //dd(request()->all());
         $this->validate($request,[
                                'designation_name'=>'unique:designations|required',
                               
                                ]);
        Designation::create([
        'department_id' => request('department_id'),
        'designation_name' => request('designation_name'),
        ]);
        
        
        return redirect('designation/view');
    }

    public function show()
    {
        $designation=Designation::join('departments','designations.department_id','=','departments.department_id')->get();
        $department=Department::get();
        //return $names;
        return view('backend.designation.viewDesignation',compact('designation', 'department'));
    }

    public function designationAjax($department)
    {
        $designation = Designation::where("department_id",$department)
                    ->pluck('designations.designation_name','designations.designation_id')->all();
        return json_encode($designation);
    }

    public function edit(Designation $designation)
    {
        //dd($designation);
        $department=Department::get();
        //dd($department);
        return view('backend.designation.editDesignation',compact('designation','department'));
    }

    public function update(Request $req,Designation $designation)
    {

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

        return redirect('designation/view');

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

but this is not related to EmployeeController

web.php

Route::get('designation/ajax/{department}','[email protected]');
Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Designation extends Model
{
    protected $fillable =['designation_name','department_id'];
   protected $primaryKey = 'designation_id';
}
Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

@nakov

using this

http://localhost/partsanalysis/public/designation/ajax/2

output:

["product manager"]
Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

@nakov using this code get error

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'undefined' for column `db_partsanalysis`.`employees`.`designation_id` at row 1 (SQL: insert into `employees` (`emp_photo`, `emp_fname`, `emp_lname`, `emp_email`, `emp_bdate`, `emp_mobile`, `emp_alt_mobile`, `emp_country`, `emp_state`, `emp_city`, `emp_address`, `emp_pincode`, `gender`, `department_id`, `designation_id`, `emp_id_proof`, `emp_username`, `password`, `login_first`, `updated_at`, `created_at`) values (download.jpg, star, Gara, [email protected], 5343-03-04, 93457346, 594645764, 105, 12, 15, pimple gurav, 411061, Female, 2, undefined, 0934826424e, kkk124, 23eq2, 0, 2019-11-25 20:55:58, 2019-11-25 20:55:58))

now in place of 0 its shows designation_id= undefined

Activity icon

Replied to On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

i selected from purchase, product manager and product manager id is 5 but still it takes 0 , shows in error

Activity icon

Started a new Conversation On Console Shows Id Values From 0 , But In Database Id Values Are Different , When Want To Store Data Id Takes 0 And Shows Error

web.php

Route::get('designation/ajax/{department}','[email protected]');

controller

public function designationAjax($department)
    {
        $designation = Designation::where("department_id",$department)
        ->pluck('designations.designation_name','designations.designation_id')->all();
        return json_encode($designation);
    }

view

 <div class="form-group">
 <h5>Select Department <span class="text-danger">*</span></h5>
         <div class="controls">
         <select class="form-control" name="department_id" onchange="getDesignation(this.value)" required>
         <option>--Select Department--</option>
                        @foreach($department as $br)
          <option value="{{$br->department_id}}">{{$br->department_name}}</option>
                         @endforeach
           </select>
       </div>
  </div>

    <div class="form-group">
      <h5>Select Designation <span class="text-danger">*</span></h5>
       <div class="controls">
                 <select class="form-control " name="designation_id" required>
                 <option>--Select Designation--</option>
                 </select>
        </div>
       </div>

script

function getDesignation(department)
                            {
                               if(department) {
                                        $.ajax({
                                            url: '{{url('/')}}/designation/ajax/'+department,
                                            type: "GET",
                                            dataType: "json",
                                            success:function(data) {
                                                //alert(data);
                                                 console.log(data);
                                        
                                                $('select[name="designation_id"]').empty();
                                                $('select[name="designation_id"]').prepend('<option value="">--Select Segment--</option>');
                                                $.each(data, function(key, value) {
                                                $('select[name="designation_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="designation_id"]').empty();
                                    }
                            }

in console

in database, designations table

when storing data gets error

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db_partsanalysis`.`employees`, CONSTRAINT `employees_designation_id_foreign` FOREIGN KEY (`designation_id`) REFERENCES `designations` (`designation_id`) ON DELETE CASCADE) (SQL: insert into `employees` (`emp_photo`, `emp_fname`, `emp_lname`, `emp_email`, `emp_bdate`, `emp_mobile`, `emp_alt_mobile`, `emp_country`, `emp_state`, `emp_city`, `emp_address`, `emp_pincode`, `gender`, `department_id`, `designation_id`, `emp_id_proof`, `emp_username`, `password`, `login_first`, `updated_at`, `created_at`) values (download.png, star, Ger, [email protected], 2000-03-04, 989775654, 957883653, 105, 12, 20, pimple gurav, 411061, Female, 2, 0, 0935883465, d343, wd5r354, 0, 2019-11-25 20:37:20, 2019-11-25 20:37:20))
Nov
22
2 weeks ago
Activity icon

Replied to The Selected Designation Id Is Invalid.

@nakov please help!!

i also not found the reason why designation_id taking 0