feat(tours): add tour listing with pagination and routers
This commit is contained in:
@@ -3,10 +3,27 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Tour;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TourController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$tours = Tour::with('tour_details')->latest()->paginate(6);
|
||||
|
||||
$tours->each(function ($tour) {
|
||||
$detail = $tour->tour_details->first();
|
||||
|
||||
$tour->nights = $detail
|
||||
? Carbon::parse($detail->start_date)->diffInDays(Carbon::parse($detail->end_date))
|
||||
: null;
|
||||
});
|
||||
|
||||
return view('tours.index', compact('tours'));
|
||||
}
|
||||
public function show(Tour $tour)
|
||||
{
|
||||
$tour->load([
|
||||
|
||||
+5
-1
@@ -33,7 +33,11 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Tour extends Model
|
||||
{
|
||||
protected $table = 'tours';
|
||||
/**
|
||||
* @var float|mixed|null
|
||||
*/
|
||||
public mixed $nights;
|
||||
protected $table = 'tours';
|
||||
|
||||
protected $casts = [
|
||||
'file_id' => 'int',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -19,6 +20,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Paginator::useBootstrapFive();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user