Kanchan186's avatar

Object of class Illuminate\Database\Eloquent\Collection could not be converted to int

i want to shows only data which active_status is 1

table

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mechanic;
use App\MechanicBank;
use App\MechanicServiceStationInfo;
use App\MechBrand;
use App\Segment;
use App\Brands;
use App\City;
use App\Country;
use App\State;

use File;

class MechanicProfileController extends Controller
{
    public function show($mechanic_id)
    {
        
//dd($company_id);
      $active_status=MechBrand::get();
      
      if($active_status==1){
 
        $mechanic=Mechanic::where('mechanics.mechanic_id',$mechanic_id)

         ->join('countries','mechanics.mech_country','=','countries.country_id')
         ->join('states','mechanics.mech_state','=','states.state_id')
         ->join('cities','mechanics.mech_city','=','cities.city_id')
         ->get();

      $mechanic_service_station_info=MechanicServiceStationInfo::where('mechanic_service_station_infos.mechanic_id',$mechanic_id)
    
         ->join('countries','mechanic_service_station_infos.service_station_country','=','countries.country_id')
         ->join('states','mechanic_service_station_infos.service_station_state','=','states.state_id')
         ->join('cities','mechanic_service_station_infos.service_station_city','=','cities.city_id')
         ->get();

      $mech_brand=MechBrand::where('mech_brands.mechanic_id',$mechanic_id)

         ->join('segments','mech_brands.segment_id','=','segments.segment_id')
         ->join('brands','mech_brands.brand_id','=','brands.brand_id')
         ->get();

      $mechanic_bank=MechanicBank::where('mechanic_banks.mechanic_id',$mechanic_id)->get();

    }
 
        return view('backend.mechanic_profile.viewMechanicProfile',compact('mechanic','mechanic_service_station_info','mechanic_bank','mech_brand'));
     }

}


view

<div class="tab-pane " id="brand" role="tabpanel">

<div class="table-responsive m-t-40">
                <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>




  </div>
</div>

MechBrandController

public function destroy(MechBrand $mech_brand)
  {
    $mech_brand::where('mech_brands.mech_brand_id',$mech_brand->mech_brand_id)
                       
            ->update([
                     
                      'active_status' => 0,
                     ]);



    return redirect('mechanic/view');
  }
0 likes
7 replies
mvd's avatar

Hi @kanchan186,

$active_status=MechBrand::get();
      
      if($active_status==1){

$active_status is the collection, not a integer.

You can test this to write dd($active_status);

Remove the above code (and the closing if statement) and change

$mechanic=Mechanic::where('mechanics.mechanic_id',$mechanic_id)

To

$mechanic=Mechanic::where(['mechanics.mechanic_id', '=', $mechanic_id], ['active_status', '=', 1])
Kanchan186's avatar

@mvd

removed this code

$active_status=MechBrand::get();

getting error

Undefined variable: active_status
mvd's avatar

@kanchan186 did you also remove

if($active_status==1){

and the closing } for this statement?

Kanchan186's avatar

@mvd now i update code like this,

$mechanic=Mechanic::where(['mechanics.mechanic_id', '=', $mechanic_id])->where('active_status',1)

still error says

Column not found: 1054 Unknown column '0' in 'where clause'
Kanchan186's avatar

@mvd how to print result of query?

$mechanic=Mechanic::where(['mechanics.mechanic_id', '=', $mechanic_id])->where('active_status',1)

         ->join('countries','mechanics.mech_country','=','countries.country_id')
         ->join('states','mechanics.mech_state','=','states.state_id')
         ->join('cities','mechanics.mech_city','=','cities.city_id')
         ->get();
mvd's avatar

@kanchan186, use the dd() function,

$mechanic=Mechanic::where(['mechanics.mechanic_id', '=', $mechanic_id])->where('active_status',1)

         ->join('countries','mechanics.mech_country','=','countries.country_id')
         ->join('states','mechanics.mech_state','=','states.state_id')
         ->join('cities','mechanics.mech_city','=','cities.city_id')
         ->get();
dd($mechanic);

Please or to participate in this conversation.