You are on page 1of 2

listing.

php
<?php

namespace App\Models;

class listing
{
public static function all()
{
return [
[
'id' => 1,
'title' => "first one",
'desc' => "Lorem ipsum dolor sit amet consectetur, adipisicing
elit. Rerum dolore tempore ipsam impedit ea doloribus quos accusantium unde
necessitatibus officiis!"
],
[
'id' => 2,
'title' => "second one",
'desc' => "Lorem ipsum dolor sit amet consectetur, adipisicing
elit. Rerum dolore tempore ipsam impedit ea doloribus quos accusantium unde
necessitatibus officiis!"
],
[
'id' => 3,
'title' => "third one",
'desc' => "Lorem ipsum dolor sit amet consectetur, adipisicing
elit. Rerum dolore tempore ipsam impedit ea doloribus quos accusantium unde
necessitatibus officiis!"
]
];
}

public static function find($id)


{
$listings = self::all();
foreach ($listings as $listing) {
if ($listing['id'] == $id) {
return $listing;
}
}
}
}

***********************************************************************************
*********************************

web.php
<?php

use Illuminate\Support\Facades\Route;
use App\Models\listing;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('main', [
'heading' => 'latest listings',
'list' => listing::find(1)
]);
});
// Route::get('/listing', function () {
// return view('main', [
// 'heading' => 'latest listings',
// 'listings' => listing::find(2)
// ]);
// });
***********************************************************************************
**************************
main.blade.php
<h1>{{$heading}}</h1>

@if (count($list) != 0)
<span>{{count($list)}}</span>
{{-- @foreach ($lists as $item)
<h2>{{$item['title']}}</h2>
<p>{{$item['desc']}}</p>
@endforeach --}}

@else
<p>no lists found</p>
@endif

You might also like