Kanchan186

Kanchan186

Software Engineer at Pune

Member Since 5 Months Ago

Pune,Maharashtra

Experience Points
10,110
Total
Experience

4,890 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
10
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 3
10,110 XP
Jan
10
2 weeks ago
Activity icon

Started a new Conversation General Error: 1005 Can't Create Table `demosql`.`posts` (errno: 150 "Foreign Key Constraint Is Incorrectly Formed") (SQL: Alter Table `posts` Add Constraint `posts_emp_id_foreign` Foreign Key (`emp_id`) References `employees` (`emp_id`) On Delete Cascade

posts table

<?php

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

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('post_id');
            $table->string('comment');
            $table->timestamps();
        });


         Schema::table('posts', function (Blueprint $table) {
            $table->integer('emp_id')->unsigned();
            $table->foreign('emp_id')->references('emp_id')->on('employees')->onDelete('cascade')->change();
           
        });
    }

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

        Schema::table('posts', function (Blueprint $table) {
          
            $table->dropForeign('posts_emp_id_foreign');
        });
    }
}

Dec
31
3 weeks ago
Activity icon

Replied to When Main Record Is Deleted How To Delete Its Related Record But " No Permanent Deletion" Changes Its Active_status=0 Only.

@tray2

i already used that and my data also deleted properly but it's a permanent Deletion. but i don't want permant deletion i just want set active_status value from 1 to 0

Activity icon

Started a new Conversation When Main Record Is Deleted How To Delete Its Related Record But " No Permanent Deletion" Changes Its Active_status=0 Only.

delete link:

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

web.php

//delete Mechanic
Route::get('mechanic/{mechanic_id}','[email protected]');

MechanicController


     public function destroy(Mechanic $mechanic_id)
    {

       // $mechanic = Mechanic::findOrFail($mechanic_id);

        //$mechanic_id::where('mechanics.mechanic_id',$mechanic_id->mechanic_id)
                  // ->where('mechanic_banks.mechanic_bank_id',$mechanic_id->mechanic_bank_id)
                
                  // ->where('mech_brands.mech_brand_id',$mechanic_id->mech_brand_id)
                
            // $mechanic_id->delete();
                   
         $mechanic_id->update([
                     
                      'active_status' => 0,
                
                     ]);

        return redirect('mechanic/view');
    }

mechanics table

mechanics table records

mechanic_banks table

mech_brands table

Activity icon

Replied to SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'mechanic_banks.mechanic_bank_id' In 'where Clause' (SQL: Update `mechanics` Set `active_status` = 0, `status` = 0, `updated_at` = 2019-12-31 18:50:16 Where `mechanics`.`mechanic_id` = 9 And `mechanic

@siangboon sir i saw this video using below code

 public function destroy(Mechanic $mechanic_id)
    {
            $mechanic_id->delete();
          
            return redirect('mechanic/view');
      }

properly delete main record with related records also.

but i don't want permanent deletion, i just want to set active_status=0

by using this code:



     public function destroy(Mechanic $mechanic_id)
    {
            $mechanic_id->update([
                     
                      'active_status' => 0,
                    //  'status'=> 0,
                     ]);

        return redirect('mechanic/view');
    }

it changes only mechanics table active_status=0 but related record active_status=1.

i want to change mechanic_bank, mech_brands, and Mechanic_service_station active_status =0 when deleting the mechanic info.

Activity icon

Started a new Conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'mechanic_banks.mechanic_bank_id' In 'where Clause' (SQL: Update `mechanics` Set `active_status` = 0, `status` = 0, `updated_at` = 2019-12-31 18:50:16 Where `mechanics`.`mechanic_id` = 9 And `mechanic

link:

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

web.php

//delete Mechanic
Route::get('mechanic/{mechanic_id}','[email protected]');

MechanicController

 public function destroy(Mechanic $mechanic_id)
    {
        $mechanic_id::where('mechanics.mechanic_id',$mechanic_id->mechanic_id)
                   ->where('mechanic_banks.mechanic_bank_id',$mechanic_id->mechanic_bank_id)
                   ->where(' mechanic_service_station_infos.service_station_info_id',$mechanic_id->service_station_info_id)
                   ->where('mech_brands.mech_brand_id',$mechanic_id->mech_brand_id)
                    
            ->update([
                     
                      'active_status' => 0,
                      'status'=> 0,
                     ]);
        return redirect('mechanic/view');
    }
Activity icon

Replied to Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

@snapey please help me! how to do this , when deletion of main record its related record also delete means how to change related record active_status=0 with main record

Dec
30
3 weeks ago
Activity icon

Replied to Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

@snapey

now i updated my code please tell me what should i do now

delete link

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

web.php

//delete Mechanic
Route::get('mechanic/{mechanic}','[email protected]');

MechanicController


     public function destroy(Mechanic $mechanic)
    {
        $mechanic::where('mechanics.mechanic_id',$mechanic->mechanic_id)
                       
            ->update([
                     
                      'active_status' => 0,
                     ]);
        return redirect('mechanic/view');
    }

but this code changes only mechanic_id status to '0' after deletion

Activity icon

Replied to Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

@snapey i already set mechanic_id as a foreign key in all related tables but the problem is i don't want permanent deletion. i just want to it changes status from 1 to 0.

Activity icon

Started a new Conversation Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

how to delete related records in database

e.g if i delete mechanic personal info then how to delete its service_station, brands and bank info at same time.

please check my code where i going wrong

delete link

<a href="{{url('/')}}/mechanic/{{$br->mechanic_id}}/{{br->mech_brand_id}}/{{br->service_station_info_id}}/{{br->mechanic_bank_id}}" onclick="return confirm('Do you want delete this record')"><i class="fas fa-trash" ></i>

web.php


//delete Mechanic
Route::get('mechanic/{mechanic}/{mechanic_service_station_info}/{mechanic_bank}/{mech_brand}','[email protected]');

MechanicController.php

public function destroy(Mechanic $mechanic,MechanicServiceStationInfo $mechanic_service_station_info,MechanicBank $mechanic_bank,MechBrand $mech_brand)
    {
        $mechanic::where('mechanics.mechanic_id',$mechanic->mechanic_id)
                 ->where('mechanic_service_station_infos.service_station_info_id',$mechanic_service_station_info->service_station_info_id)
                 ->where('mechanic_banks.mechanic_bank_id',$mechanic_bank->mechanic_bank_id)
                 ->where('mech_brands.mech_brand_id',$mech_brand->mech_brand_id)

            ->update([
                     
                      'active_status' => 0,
                     ]);
        return redirect('mechanic/view');
    }
Activity icon

Started a new Conversation Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No Message

please check where i going wrong

edit link

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

web.php

//edit segment
Route::get('segment/{segment}/edit','[email protected]');
Route::patch('segment/{segment}','[email protected]');

editsegment.blade.php

<form class="m-t-40" method="post" action="{{url('/')}}/segment/{{$segment->segment_id}}" 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" required data-validation-required-message="This field is required">
                                            
                                           @foreach($industry as $br)
                                            
                                                @if($br->industry_id == $segment->industry_id )
                                                     <option value="{{$br->industry_id}}" selected >{{$br->industry_name}}</option>
                                                @else
                                                     <option value="{{$br->industry_id}}">{{$br->industry_name}}</option>
                                                @endif

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




                                      <div class="form-group">
                                        <h5>Segment Name <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="segment_name" id ="segment_name" class="form-control"  value="{{ $segment->segment_name}}" 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>

segmentController.php

public function edit(Segment $segment)
    {
        //dd($segment);

        $industry=Industry::where('industries.active_status', '=', 1)->get();
        //dd($industry);
        return view('backend.segment.editSegment',compact('segment','industry'));
    }

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

    }
Dec
23
1 month ago
Activity icon

Replied to How To Set "required "validation For Multiple Dependent Dynamic Drop-down(values Comes From Database) List In Javascript

@van-india sir

there is dynamic dependent drop down and values comes from database please suggest me this type of solution

Activity icon

Started a new Conversation How To Set "required "validation For Multiple Dependent Dynamic Drop-down(values Comes From Database) List In Javascript

view


<div class="form-group">
            <h5>Select Country <span class="text-danger">*</span></h5>
            <div class="controls">
                                            
                <select class="form-control" name="emp_country" id="emp_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="emp_state" id="emp_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="emp_city" id="emp_city" required>
               <option>--Select City--</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="emp_state"]').empty();
                                                $('select[name="emp_state"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="emp_state"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="emp_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="emp_city"]').empty();
                                                $('select[name="emp_city"]').prepend('<option value="">--Select City--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="emp_city"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

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

Activity icon

Replied to Checkbox Are Not Displayed (shows Only Value)

@snapey which type of css required to display checkboxes properly

Dec
20
1 month ago
Activity icon

Replied to Checkbox Are Not Displayed (shows Only Value)

@snapey

this CSS is used for checkbox in style.css

[type=checkbox]:checked, [type=checkbox]:not(:checked) {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

when i delete left and opacity , it display like this

Activity icon

Replied to Checkbox Are Not Displayed (shows Only Value)

@snapey how to set CSS in javascript code

Activity icon

Started a new Conversation How To Set Validation To Dynamic Drop Down In Laravel

code:

addEmp view

                <div class="form-group">
                                        <h5>Employee alternate mobile <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="emp_alt_mobile" id ="emp_alt_mobile" class="form-control" required data-validation-containsnumber-regex="(\d)+" data-validation-containsnumber-message="No Characters Allowed, Only Numbers" maxlength="10"> </div>
                                       
                                    </div>
 <div class="form-group">
            <h5>Select Country <span class="text-danger">*</span></h5>
            <div class="controls">
                                            
                <select class="form-control" name="emp_country" id="emp_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="emp_state" id="emp_state" onchange="getCity(this.value) " required>
                <option>--Select State--</option>
                 @foreach($state as $st)
                <option value="{{$st->state_id}}">{{$st->state_name}}</option>
                @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="emp_city" id="emp_city" required>
               <option>--Select City--</option>
               
               </select>
           </div>
     </div>

                        <div class="form-group">
                                        <h5>Employee Address <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            <input type="text" name="emp_address" id ="emp_address" class="form-control" required data-validation-required-message="This field is required"> </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="emp_state"]').empty();
                                                $('select[name="emp_state"]').prepend('<option value="">--Select State--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="emp_state"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

                                            }
                                        });
                                    } else{
                                         $('select[name="emp_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="emp_city"]').empty();
                                                $('select[name="emp_city"]').prepend('<option value="">--Select City--</option>');
                                                $.each(data, function(key, value) {
                                                    $('select[name="emp_city"]').append('<option value="'+ key +'">'+ value +'</option>');
                                                });

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

EmployeeController


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Department;
use App\Designation;
use App\Employee;
use App\City;
use App\Country;
use App\State;
use File;

class EmployeeController extends Controller
{
     public function __construct()
    {
        $this->middleware('auth');
    }
    public function Add()
    {

        $department=Department::where('departments.active_status', '=', 1)->get();
        $designation=Designation::where('designations.active_status', '=', 1)->get();
        $employee=Employee::get();
        $country=Country::where('country_name','India')->first();
        $state=State::where('country_id',$country->country_id)->get();
        $city = City::all();
        $country=Country::get();

        return view('backend.employee.addEmp',compact('department','employee','designation','state','city','country'));

    }

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

        return json_encode($city);


    }

}
Dec
17
1 month ago
Activity icon

Started a new Conversation Checkbox Are Not Displayed (shows Only Value)

when i unchecked left alignment and opacity default checkboxes shows

please suggest me which inline CSS i need to add in code

view

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

                                
                                      <div class="form-group">
                                        <h5>Segment<span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                @foreach($segment as $sg)
                                <ul><li>
                               <input type="checkbox" value="{{$sg->segment_id }}" name="sg[{{$sg->segment_id }}]" id="{{$sg->segment_id }}" onclick="getBrand1(this.id)" class="test" >

                                <label  for="{{ $sg->segment_id }}">
                                <p>{{$sg->segment_name }}</p></label></li></ul>
                                
                                @endforeach
                                        </div>

                                       
                                    </div> 

                                    <div id="brands" >
                                        <ul>
                                        <li>
                                        <input type="checkbox" >
                                        </li>   
                                       </ul>  
                                   
                                     </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 getBrand1(id)
   {
          //  alert('Choose brands!');

 if(document.getElementById(id).checked)  
   {  
       
       $.ajax({
        url: 'http://localhost/partsanalysis/public/brand/Ajax/'+id,
       type: "GET",
       dataType: "json",
        error: function(data, errorThrown)
          {
              console.log('request failed :'+errorThrown);
          },
       success:function(result) {
         console.log(result);
       // alert(result);


                $.each(result, function(index, value) { 

                 console.log(result, index, value);
 
                 var markup = "<ul><li><input type='checkbox' name='br[" + value.brand_id + "]' value='" + value.brand_id + "'></li><li>" + value.brand_name + "</li></ul>";
                        
                 $("#brands").append(markup);
                 });

                   }
              });
          }     
      
        else
            {
                $("#brands").html(""); 
            }
        

        }

</script>
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`empzone_mappings`, CONSTRAINT `empzone_mappings_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`emp

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

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

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`empzone_mappings`, CONSTRAINT `empzone_mappings_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`emp

now output shows like that

{4: "Manager"}4: "Manager"__proto__: Object

employee_zone_mapping:954 
(2) [{…}, {…}]
0: {emp_fname: "kanchan", emp_lname: "nawkar", emp_id: 18}
1: {emp_fname: "Riya", emp_lname: "Patil", emp_id: 23}
length: 2__proto__: Array(0)
Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`empzone_mappings`, CONSTRAINT `empzone_mappings_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`emp

employees table

and i updated code gives this output

public function employeeAjax($designation)
    {
        $employee = Employee::where('employees.active_status', '=', 1)
                    ->where("designation_id",$designation)
                    ->pluck('employees.emp_fname','employees.emp_id')->all();
        return json_encode($employee);
    }

but in add view it takes only employee first name but i want both first name and last name

Activity icon

Replied to SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`empzone_mappings`, CONSTRAINT `empzone_mappings_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`emp

@tykus

array:5 [▼
  "_token" => "tnjiyNbRqsOd5Kaf5BCP9NhqMXuBFVv8ZDp6dpBV"
  "department_id" => "1"
  "designation_id" => "4"
  "emp_id" => "0"
  "zo" => array:1 [▶]
]

it takes emp_id=0 due to this may be error occurs

Activity icon

Started a new Conversation SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails (`db_partsanalysis`.`empzone_mappings`, CONSTRAINT `empzone_mappings_emp_id_foreign` FOREIGN KEY (`emp_id`) REFERENCES `employees` (`emp

controller

 public function employeeAjax($designation)
    {
        $employee = Employee::where('employees.active_status', '=', 1)
                    ->where("designation_id",$designation)
                    ->select('employees.emp_fname','employees.emp_lname','employees.emp_id')->get();
        return json_encode($employee);
    }

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"onchange="getEmployee(this.value)" required="" >
                                                <option>--Select Designation--</option>
                                         
                                        </select>
                                        </div>
                                       
                                    </div>

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

                                        </div>
                                       
                                    </div>

script

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

                                            }
                                        });
                                    } else{
                                         $('select[name="emp_id"]').empty();
                                    }
                            } 
Dec
16
1 month ago
Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'nawkar' For Column `db_partsanalysis`.`empzone_mappings`.`emp_id` At Row 1 (SQL: Insert Into `empzone_mappings` (`emp_id`, `department_id`, `designation_id`, `active_status`, `zone_i

@sinnbeck

when i used this code it takes emp_id= nawkar but it's wrong

 public function employeeAjax($designation)
    {
        $employee = Employee::where('employees.active_status', '=', 1)
                    ->where("designation_id",$designation)
                    ->pluck('employees.emp_fname','employees.emp_lname','employees.emp_id')->all();
        return json_encode($employee);
    }
Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'nawkar' For Column `db_partsanalysis`.`empzone_mappings`.`emp_id` At Row 1 (SQL: Insert Into `empzone_mappings` (`emp_id`, `department_id`, `designation_id`, `active_status`, `zone_i

now the problem is, in add view in employee dynamic drop down shows only employee firstname, but i want both first name as well as last name

by using this code above output comes

     public function employeeAjax($designation)
    {
        $employee = Employee::where('employees.active_status', '=', 1)
                    ->where("designation_id",$designation)
                    ->pluck('employees.emp_fname','employees.emp_id')->all();
        return json_encode($employee);
    }
Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'nawkar' For Column `db_partsanalysis`.`empzone_mappings`.`emp_id` At Row 1 (SQL: Insert Into `empzone_mappings` (`emp_id`, `department_id`, `designation_id`, `active_status`, `zone_i

@sinnbeck

now it takes proper id

array:5 [▼
  "_token" => "sDbyJC52Jw6ty0qVyoDnnEk5sWRpxMeuvi4zHzDn"
  "department_id" => "1"
  "designation_id" => "4"
  "emp_id" => "18"
  "zo" => array:1 [▶]
]

first it takes nawkar in for id value so it shows error

Activity icon

Replied to SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'nawkar' For Column `db_partsanalysis`.`empzone_mappings`.`emp_id` At Row 1 (SQL: Insert Into `empzone_mappings` (`emp_id`, `department_id`, `designation_id`, `active_status`, `zone_i

@sinnbeck store method


   public function store(Request $request)
    {
        //dd(request()->all());
        
      foreach(request('zo') as $zo_id) 
       { 
        EmpzoneMapping::create([
        'emp_id'=>request('emp_id'),    
        'department_id' => request('department_id'),
        'designation_id' => request('designation_id'),
    'active_status'=>1,
        'zone_id' => $zo_id,

        
        ]);
      } 
    
      $department=Department::get();
        $designation=Designation::get();
        $zone=zone::get();
        $employee=employee::get();

        array($request->get('zone_id'));

      //dd('hi');
        
        return redirect('employee_zone_mapping/view');
    }
Activity icon

Awarded Best Reply on How To Fetch Gender Value From Database Using Foreach

i solved this problem by using this code

div class="form-group">
                                        <h5>Gender <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                            <div class="controls">
                                            
                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio1" value="Male"{{ $employee->gender == 'Male' ? 'checked' : ''}} required>


                                            <label class="form-check-label" for="inlineRadio1" selected>Male</label>

                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio2"  value="Female" {{ $employee->gender == 'Female' ? 'checked' : ''}} required>

                                             <label class="form-check-label" for="inlineRadio2">Female</label>

                                            

                                             </div>

                                        </div>
                                       
                                    </div>  

it works..

Activity icon

Replied to How To Fetch Gender Value From Database Using Foreach

i solved this problem by using this code

div class="form-group">
                                        <h5>Gender <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                            <div class="controls">
                                            
                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio1" value="Male"{{ $employee->gender == 'Male' ? 'checked' : ''}} required>


                                            <label class="form-check-label" for="inlineRadio1" selected>Male</label>

                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio2"  value="Female" {{ $employee->gender == 'Female' ? 'checked' : ''}} required>

                                             <label class="form-check-label" for="inlineRadio2">Female</label>

                                            

                                             </div>

                                        </div>
                                       
                                    </div>  

it works..

Activity icon

Started a new Conversation How To Fetch Gender Value From Database Using Foreach

view

<div class="form-group">
                                        <h5>Gender <span class="text-danger">*</span></h5>
                                        <div class="controls">
                                            
                                            <div class="controls">
                                            @foreach($employee as $br)    
                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio1" value="Male"  required>

                                            <label class="form-check-label" for="inlineRadio1" selected>Male</label>

                                            <input class="form-check-input" type="radio" name="gender" id="inlineRadio2" value="Female" required>

                                             <label class="form-check-label" for="inlineRadio2">Female</label>

                                             @endforeach

                                             </div>

                                        </div>
                                       
                                    </div>  
Activity icon

Started a new Conversation SQLSTATE[22007]: Invalid Datetime Format: 1366 Incorrect Integer Value: 'nawkar' For Column `db_partsanalysis`.`empzone_mappings`.`emp_id` At Row 1 (SQL: Insert Into `empzone_mappings` (`emp_id`, `department_id`, `designation_id`, `active_status`, `zone_i

controller


     public function employeeAjax($designation)
    {
        $employee = Employee::where('employees.active_status', '=', 1)
                    ->where("designation_id",$designation)
                    ->pluck('employees.emp_fname','employees.emp_lname','employees.emp_id')->all();
        return json_encode($employee);
    }

view

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

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

                                        </div>
                                       
                                    </div>


script


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

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

Dec
13
1 month ago
Activity icon

Replied to When I Deleted Data It Status Becomes '0', And When I Fetch Data, It Also Shows Deleted Data. Please Check My Code,where My Condition Is Correct Or Not?

@snapey this code i used for dynamic dropdown

<script type="text/javascript">


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

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

Replied to When I Deleted Data It Status Becomes '0', And When I Fetch Data, It Also Shows Deleted Data. Please Check My Code,where My Condition Is Correct Or Not?

Add new brand 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 class="form-control" name="industry_id" onchange="getSegment(this.value)" required data-validation-required-message="This field is required">
                                            
                                            <option>--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 Logo <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>
Activity icon

Replied to When I Deleted Data It Status Becomes '0', And When I Fetch Data, It Also Shows Deleted Data. Please Check My Code,where My Condition Is Correct Or Not?

public function destroy(Brands $brand)
    {
        $files=public_path().'/brand_logos/'.$brand->brand_logo;
            File::delete($files);

        $brand::where('brands.brand_id',$brand->brand_id)
                       
            ->update([
                     
                      'active_status' => 0,
                     ]);
        return redirect('brand/view');
    }

this code works in database records are updated ,

Activity icon

Replied to How To Fetch Non Deleted Data From Database

because no ones reply there, i thought adding new title may be helps someone :)