Tochino's avatar

please i really need some one to fixed this for me Trying to get property 'id' of non-object (View: C:\xampp\htdocs\thrilzs\resources\views\layouts\app.blade.php)

				<h4>Cleaning Services</h4>

				<ul class="marker-list">

					@foreach ($services as $item)

				<li><a href="/service {{ $item->id }}">{{ $item->title }}</a></li>

					@endforeach

				</ul>

			</div>

View

View name C:\xampp\htdocs\thrilzs\resources\views/layouts/app.blade.php View data

errors

    Illuminate\Support\ViewErrorBag {#292
      #bags: []
    }

obLevel

    1

services

    App\Models\services {#303
      #table: "services"
      #fillable: array:3 [
        0 => "title"
        1 => "info"
        2 => "image"
      ]
      #connection: "mysql"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:6 [
        "id" => 1
        "title" => "House cleaning"
        "info" => """
          <p><br></p><p>Our cleaning system sets us apart. Our customers keep coming back to \r\n
          us, because we provide services that work and keep their homes and \r\n
          apartments clean, right down to the little details. This extensive \r\n
          cleaning system, which we call our Detail-Clean Rotation System, which \r\n
          has been proven to be effective in more than five million cleans!</p><p>\r\n
          \t\t\t\t\t\t<br></p><h5>How does our apartment cleaning program work?</h5><p>\r\n
          \t\t\t\t\t\t<br></p><p>We start with a thorough detail-clean throughout your house \r\n
          over the course of the first two cleans. On the first clean, our maid \r\n
          service will thoroughly clean your apartment, with special attention on \r\n
          your kitchen and bathrooms. On the second session, we'll clean your \r\n
          entire apartment, but this time we'll provide detail-clean services in \r\n
          your sleeping and living areas. We'll continue to maintain this \r\n
          detail-clean level throughout your home throughout our next visits by \r\n
          providing deep cleaning services on a rotating basis.</p><p>\r\n
          \t\t\t\t\t\t<br></p><p>Every time we clean, we'll provide services that include the following:</p><p>\r\n
          \t\t\t\t\t\t<br></p><ul class="marker-list"><li><b>Bathrooms</b>\r\n
          \t\t\t\t\t\t\t\t<br>Cobwebs removed, dusting, floors cleaned, toilets cleaned, \r\n
          mirrors / chrome fixtures cleaned, shower doors cleaned, tile walls, \r\n
          bathtub / showers cleaned</li><li><b>Sleeping Areas</b>\r\n
          \t\t\t\t\t\t\t\t<br> Surfaces hand wiped, floors cleaned, general dusting, cobwebs removed, doors and door frames spot cleaned</li><li><b>Living Areas</b>\r\n
          \t\t\t\t\t\t\t\t<br>Surfaces hand wiped, cobwebs removed, doors and door frames spot cleaned, general dusting, floors cleaned</li><li><b>Kitchen</b>\r\n
          \t\t\t\t\t\t\t\t<br>Countertops cleaned, outside of range hood cleaned, top and \r\n
          front of range cleaned, drip pans / glass top surfaces wiped, sinks \r\n
          cleaned and chrome shined, fronts of all appliances cleaned, general \r\n
          dusting, cobwebs removed, microwave wiped out, doors and door frames \r\n
          spot cleaned</li></ul><p><br></p>
          """
        "image" => "AhYq8NCeycZMrEKa27Ve9ocGVOqu6QnLWSnKymz2.jpeg"
        "created_at" => "2020-03-15 02:09:45"
        "updated_at" => "2020-03-15 02:09:45"
      ]
      #original: array:6 [
        "id" => 1
        "title" => "House cleaning"
        "info" => """
          <p><br></p><p>Our cleaning system sets us apart. Our customers keep coming back to \r\n
          us, because we provide services that work and keep their homes and \r\n
          apartments clean, right down to the little details. This extensive \r\n
          cleaning system, which we call our Detail-Clean Rotation System, which \r\n
          has been proven to be effective in more than five million cleans!</p><p>\r\n
          \t\t\t\t\t\t<br></p><h5>How does our apartment cleaning program work?</h5><p>\r\n
          \t\t\t\t\t\t<br></p><p>We start with a thorough detail-clean throughout your house \r\n
          over the course of the first two cleans. On the first clean, our maid \r\n
          service will thoroughly clean your apartment, with special attention on \r\n
          your kitchen and bathrooms. On the second session, we'll clean your \r\n
          entire apartment, but this time we'll provide detail-clean services in \r\n
          your sleeping and living areas. We'll continue to maintain this \r\n
          detail-clean level throughout your home throughout our next visits by \r\n
          providing deep cleaning services on a rotating basis.</p><p>\r\n
          \t\t\t\t\t\t<br></p><p>Every time we clean, we'll provide services that include the following:</p><p>\r\n
          \t\t\t\t\t\t<br></p><ul class="marker-list"><li><b>Bathrooms</b>\r\n
          \t\t\t\t\t\t\t\t<br>Cobwebs removed, dusting, floors cleaned, toilets cleaned, \r\n
          mirrors / chrome fixtures cleaned, shower doors cleaned, tile walls, \r\n
          bathtub / showers cleaned</li><li><b>Sleeping Areas</b>\r\n
          \t\t\t\t\t\t\t\t<br> Surfaces hand wiped, floors cleaned, general dusting, cobwebs removed, doors and door frames spot cleaned</li><li><b>Living Areas</b>\r\n
          \t\t\t\t\t\t\t\t<br>Surfaces hand wiped, cobwebs removed, doors and door frames spot cleaned, general dusting, floors cleaned</li><li><b>Kitchen</b>\r\n
          \t\t\t\t\t\t\t\t<br>Countertops cleaned, outside of range hood cleaned, top and \r\n
          front of range cleaned, drip pans / glass top surfaces wiped, sinks \r\n
          cleaned and chrome shined, fronts of all appliances cleaned, general \r\n
          dusting, cobwebs removed, microwave wiped out, doors and door frames \r\n
          spot cleaned</li></ul><p><br></p>
          """
        "image" => "AhYq8NCeycZMrEKa27Ve9ocGVOqu6QnLWSnKymz2.jpeg"
        "created_at" => "2020-03-15 02:09:45"
        "updated_at" => "2020-03-15 02:09:45"
      ]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [
        0 => "*"
      ]
    }
0 likes
20 replies
Snapey's avatar

$services seems to be a single model, so you cannot use it like a collection (with @foreach)

Please show how you extract this from the database

Tochino's avatar

Services = services::findOrFail($id);

Tochino's avatar

// services public function services() { $services = Services::all(); return view('frontend.services')->with('services', $services); }

Sergiu17's avatar
$services = services::findOrFail($id);
$services = Services::all();

these are two different things..you can't loop over first $services - also I suggest you to rename it to $service (singular)

$service = services::findOrFail($id);

{{ $service->id }}
$services = Services::all();

@foreach($services as $item)
	{{ $item->id }}
@endforeach
Tochino's avatar

I tried renaming, but still not working

Sergiu17's avatar

@tochino if you are trying to display a model by ID then:

// controller
$service = Services::findOrFail($id);

// view
{{ $service->id }}

if you are trying to display all models

// controller
$services = Services::all();

// view
@foreach($services as $item)
	{{ $item->id }}
@endforeach
Tochino's avatar

Now am getting this Class services not found

Sergiu17's avatar

I guess you have to import the class, add this at the top in you controller

user App\Services;
Tochino's avatar

namespace App\Http\Controllers\Frontend;

use App\Models\services; use App\Http\Controllers\Controller; use Illuminate\Http\Request;

class Frontendcontroller extends Controller { public function index() { return view('frontend.index');

}

public function about()
{
    return view('frontend.about');
}

// services
public function services()
{
    $services = Services::all();
    return view('frontend.services')->with('services', $services);
}

public function servicesPage(Request $request, $id)
{
    $services = Services::findOrFail($id);
    return view('frontend.service')->with('services', $services);
}

public function contact()
{
    return view('frontend.contact');
}

public function quote()
{
    return view('frontend.quote');
}

}

Sergiu17's avatar

Make sure your model has App\Models namespace, everything else looks OK,

// services
public function services()
{
    $services = Services::all();

    return view('frontend.services')->with('services', $services);
}
// frontend.services
@foreach($services as $item)
	{{ $item->id }}
@endforeach
// service
public function servicesPage(Request $request, $id)
{
    $service = Services::findOrFail($id);

    return view('frontend.service')->with('service', $service);
}
// frontend.service
{{ $service->id }}
Snapey's avatar

you are importing services but trying to use Services

lettercase matters...

1 like
Snapey's avatar

how does this one post get 2250 views in one hour? Perhaps someone has refresh monkey on it?

By the time I write this it had gone up another 50

jlrdw's avatar

@snapey namespaces are case-insensitive that shouldn't have caused the problem.

But I agree to make the case the same, just better programming practice.

Please or to participate in this conversation.