Я новичок в PHP и laravel, поэтому я хотел задать простой вопрос. Предположим, у меня есть несколько слов, например «Hello I Am Nutan», и я принес их из своей базы данных, поэтому могу ли я изменить это на «hello-i-am-nutan». Я пытаюсь реализовать это в своем URL-адресе в моем проекте, где я хочу сделать свое имя пакета для URL-адреса пакета и в соответствии с URL-адресом правильные данные, которые будут отображаться на следующей странице, поэтому кто-нибудь может сказать мне, как изменить "Здравствуйте, я Am Nutan "на" hello-i-am-nutan "в blade. php файл.
My Controller:
public function package($package_name){
// your code goes here
}
public function packages(){
$packages = Packages::all();
$converted = Str::kebab();
return view('pages.packages',compact('packages'),compact('converted'));
}
My blade. php file:
@extends('layouts.layout')
@section('style')
<!-- Owl Carousel -->
<link rel="stylesheet" href="css/owl.carousel.min.css" />
<link rel="stylesheet" href="css/owl.theme.default.min.css" />
<link rel="stylesheet" href="css/packages.css">
@endsection
@section('content')
<section id="wrapper" class="skewed">
<div class="layer bottom"></div>
<div class="layer top">
<div class="content-wrap">
<div class="content-body">
<h1>Packages</h1>
<p class="text-capitalize">Scroll Down to learn more about packages</p>
</div>
</div>
</div>
</section>
<!-- Property to Buy Start -->
<section class="packages mt-5">
<div class="container">
<div class="package-heading text-center mb-4">
<h2 class="font-weight-bold text-capitalize">Tour Packages</h2>
<p>Check out all of our latest tour packages.</p>
</div>
<div class="packages owl-carousel owl-carousel2 row mb-5">
@foreach ($packages as $package)
@if ($package->Package_Type == 'Tour')
<div class="col-md-3">
<div class="package shadow" >
<div class="package-image">
<img src="{{$package->Package_Image}}" alt="Kathmandu - Pokhara Trek">
<div class="package_hover">
<a href="{{ route('package.name',['package_name' => $converted]) }}">Read More</a>
<img src="img/svg/heart.svg" alt="" >
</div>
</div>
<div class="package-description">
<div class="package-name">
<h5 class="font-weight-bold text-capitalize">{{$package->Package_Name}} {{$package->Package_Type}}</h5>
</div>
<div class="package-short-description">
<p class="text-justify">{{$package->Package_Short_Description}}</p>
</div>
<div class="package-detail d-flex justify-content-between font-weight-bold">
<span><i class="far fa-clock"></i> Duration: {{$package->Package_Duration}}Days</span>
<span><i class="fas fa-bars"></i> Level:{{$package->Package_Level}}</span>
</div>
<div class="package-price pt-2">
<span class="font-weight-bold">Tour Price<br/>${{$package->Package_Price}}</span>
</div>
</div>
</div>
</div>
@endif
@endforeach
</div>
</div>
</section>
<!-- Property to Buy End -->
<!-- Property to Rent Start -->
<section class="packages">
<div class="container">
<div class="package-heading text-center mb-4">
<h2 class="font-weight-bold text-capitalize">Trek Packages</h2>
<p>Check out all of our latest treaking packages.</p>
</div>
<div class="owl-carousel owl-carousel2 row mb-5">
@foreach ($packages as $package)
@if ($package->Package_Type == 'Trek')
<div class="col-md-3">
<div class="package shadow" >
<div class="package-image">
<img src="{{$package->Package_Image}}" alt="Kathmandu - Pokhara Trek">
<div class="package_hover">
<a href="{{ route('package.name',['package_name' => $converted]) }}">Read More</a>
<img src="img/svg/heart.svg" alt="" >
</div>
</div>
<div class="package-description">
<div class="package-name">
<h5 class="font-weight-bold text-capitalize">{{$package->Package_Name}} {{$package->Package_Type}}</h5>
</div>
<div class="package-short-description">
<p class="text-justify">{{$package->Package_Short_Description}}</p>
</div>
<div class="package-detail d-flex justify-content-between font-weight-bold">
<span><i class="far fa-clock"></i> Duration: {{$package->Package_Duration}}Days</span>
<span><i class="fas fa-bars"></i> Level:{{$package->Package_Level}}</span>
</div>
<div class="package-price pt-2">
<span class="font-weight-bold">Tour Price<br/>${{$package->Package_Price}}</span>
</div>
</div>
</div>
</div>
@endif
@endforeach
</div>
</div>
</section>
<!-- Property to rent End -->
@endsection
@section('script')
{{-- Owl Carousel js --}}
<script src="js/owl.carousel.min.js"></script>
<script src="js/packages.js"></script>
@endsection
я его в <a href="{{url('/package/')}}">Read More</a>
Хорошо, я не проложил маршруты для следующей страницы, но это будет / package / something
Route::prefix('/package')->group(function() {
Route::get('/{package_name}', 'PackageController@package')->name('package.name');
});
Но кажется, что Package_Name - это не данные базы данных, а просто обычный текст, как перенести Package_Name в контроллер внутри kebab. Мой файл миграции:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePackagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('packages', function (Blueprint $table) {
$table->id();
$table->string('Package_Banner_Image');
$table->string('Package_Image');
$table->string('Package_Type');
$table->string('Package_Name')->unique();
$table->integer('Package_Price');
$table->integer('Package_Duration');
$table->string('Package_Level');
$table->string('Package_Short_Description');
$table->text('Day_One');
$table->text('Day_Two')->nullable();
$table->text('Day_Three')->nullable();
$table->text('Day_Four')->nullable();
$table->text('Day_Five')->nullable();
$table->text('Day_Six')->nullable();
$table->text('Day_Seven')->nullable();
$table->text('Day_Eight')->nullable();
$table->text('Day_Nine')->nullable();
$table->text('Day_Ten')->nullable();
$table->text('Day_Eleven')->nullable();
$table->text('Day_Twelve')->nullable();
$table->text('Day_Thirteen')->nullable();
$table->text('Day_Fourteen')->nullable();
$table->text('Day_Fiveteen')->nullable();
$table->text('Cost_Includes_One');
$table->text('Cost_Includes_Two')->nullable();
$table->text('Cost_Includes_Three')->nullable();
$table->text('Cost_Includes_Four')->nullable();
$table->text('Cost_Includes_Five')->nullable();
$table->text('Cost_Includes_Six')->nullable();
$table->text('Cost_Includes_Seven')->nullable();
$table->text('Cost_Includes_Eight')->nullable();
$table->text('Cost_Includes_Nine')->nullable();
$table->text('Cost_Includes_Ten')->nullable();
$table->longText('Package_Location');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('packages');
}
}