如何更改句子并将其加入blade.php文件? [英] How can i change the sentence and join them in a blade.php file?

查看:68
本文介绍了如何更改句子并将其加入blade.php文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP和laravel的新手,所以我想问一个简单的问题.假设我有几个字,例如"Hello I Am Nutan"并且我已经从数据库中将其导入,因此可以将其更改为"hello-i-am-nutan".我正在尝试在我的项目中的URL中实现此目标,在该项目中,我想使我的软件包名称成为软件包URL,并根据URL正确显示下一页中显示的数据,因此有人可以告诉我如何更改"Hello"我是Nutan"到你好,我的花生"在blade.php文件中.

I am new to PHP and laravel so i wanted to ask a simple question. Suppose i have a few words such as "Hello I Am Nutan" and i have brought it in from my database so can i change that to "hello-i-am-nutan". I am trying to implement this in my URL in my project where i want to make my package name to package URL and according to the URL the proper data to be shown in next page so can some one tell me how to change the "Hello I Am Nutan" to "hello-i-am-nutan" in blade.php file.

我的控制器:

 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'));
}

我的blade.php文件:

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

Okay i have not made my routes for the next page but it will be /package/something

Route::prefix('/package')->group(function() {
    Route::get('/{package_name}', 'PackageController@package')->name('package.name');
});

但是,Package_Name似乎不是数据库数据,而仅仅是纯文本,如何在kebab中将Package_Name带入控制器. 我的迁移文件:

But it seems that Package_Name is not database data but just plain text how to bring Package_Name in controller inside kebab. My Migration file:

<?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');
    }
}

推荐答案

刀片文件中

<?php  $converted = Illuminate\Support\Str::kebab($package['Package_Name']);?>
                           <a href="{{ route('package-info',['package_name' => $converted]) }}">Read More</a>

在路由文件中

Route::get('/package-info/{package_name}', 'master\webEventController@package_info')->name('package-info');

在控制器文件中

public function package_info($package_name) {
    $package_name = str_replace('-', ' ', $package_name);
    $package_info = Packages::where('package_name', $package_name)->first();
    return view('')->with('package_info', $package_info);
}

这篇关于如何更改句子并将其加入blade.php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆