【问题标题】:How i remove authentication system from a controller我如何从控制器中删除身份验证系统
【发布时间】:2021-12-29 09:48:54
【问题描述】:

我想从控制器中删除身份验证系统。

这是我的控制器代码。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\rfq;
use App\Models\customer_rfq;

class ShowRfqController extends Controller
{
    public function inforfq($name)
    {
        $rfq = rfq::find($name);
        return view('frontend.sellershowrfq',compact('rfq'));
    }

    public function customer_inforfq($name)
    {
        $customer_rfq = customer_rfq::find($name);
        return view('frontend.customershowrfq',compact('customer_rfq'));
    }
}

这是我的模型代码。

这是 customer_rfq 模型的代码。

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class customer_rfq extends Model
{
    use HasFactory;
    protected $table = 'customer_rfq';
    protected $fillable = [
        'name',
        'description',
        'Price',
        'MobileNo',
        'quantity',
        'image',
    ];
}

这是rfq模型的代码。

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App;

class rfq extends Model
{
    use HasFactory;
    protected $table = 'rfq';
    protected $fillable = [
        'name',
        'description',
        'Price',
        'MobileNo',
        'quantity',
        'image'
    ];
}

这是我的观点代码。

这是我的客户rfqshow.blade.php 查看代码。

@extends('frontend.layouts.app')

@section('content')
    <section class="mb-4 pt-3">
        <div class="container">
            <div class="bg-white shadow-sm rounded p-3">
                <div style="margin-left: 50px; margin-top: 35px;" class="row">
                    <div class="col-xl-5 col-lg-6 mb-4">
                        <div class="sticky-top z-3 row gutters-10">
                            <div class="col order-1 order-md-2">
                                <div class="aiz-carousel product-gallery" data-nav-for='.product-gallery-thumb' data-fade='true' data-auto-height='true'>
                                    <div class="carousel-box img-zoom rounded">
                                        <img class="img-fluid lazyload" src="{{ static_asset('assets/img/placeholder.jpg') }}" data-src="{{ uploaded_asset($customer_rfq->image) }}" onerror="this.onerror=null;this.src='{{ static_asset('assets/img/placeholder.jpg') }}';" >
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col">
                        <h2 style="text-transform: capitalize;">
                            <b> {{ $customer_rfq->name }} </b>
                        </h2>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;1">{{ translate('Approx Price')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;" name="price">
                                <b> Rs. {{ $customer_rfq->Price }}.00/- </b>
                            </h2>
                        </div>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;">{{ translate('Quantity')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;" name="quantity">
                                <b>{{ $customer_rfq->quantity }}</b>
                            </h2>
                        </div>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;1">{{ translate('Total Price')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;">
                                <b>Rs. {{ $customer_rfq->quantity*$customer_rfq->Price }}.00/-</b>
                            </h2>
                        </div>
                        <div class="row no-gutters mt-4">
                            <div class="col-sm-2">
                                <div class="opacity-50 my-2">{{ translate('Share')}}:</div>
                            </div>
                            <div class="col-sm-10">
                                <div class="aiz-share"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

这是我的sellershoerfq.blade.php 查看代码。

@extends('frontend.layouts.app')

@section('content')
    <section class="mb-4 pt-3">
        <div class="container">
            <div class="bg-white shadow-sm rounded p-3">
                <div style="margin-left: 50px; margin-top: 35px;" class="row">
                    <div class="col-xl-5 col-lg-6 mb-4">
                        <div class="sticky-top z-3 row gutters-10">
                            <div class="col order-1 order-md-2">
                                <div class="aiz-carousel product-gallery" data-nav-for='.product-gallery-thumb' data-fade='true' data-auto-height='true'>
                                    <div class="carousel-box img-zoom rounded">
                                        <img class="img-fluid lazyload" src="{{ static_asset('assets/img/placeholder.jpg') }}" data-src="{{ uploaded_asset($rfq->image) }}" onerror="this.onerror=null;this.src='{{ static_asset('assets/img/placeholder.jpg') }}';" >
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col">
                        <h2 style="text-transform: capitalize;">
                            <b> {{ $rfq->name }} </b>
                        </h2>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;">{{ translate('Approx Price')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;" name="price">
                                <b> Rs. {{ $rfq->Price }}.00/- </b>
                            </h2>
                        </div>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;">{{ translate('Quantity')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;" name="quantity">
                                <b>{{ $rfq->quantity }}</b>
                            </h2>
                        </div>
                        <hr>
                        <div class="col-sm-2">
                            <div class="opacity-50 my-2" style="font-size: 15px;">{{ translate('Total Price')}}:
                            </div>
                        </div>
                        <div class="col-sm-10">
                            <h2 style="color: red; font-style:;">
                                <b>Rs. {{ $rfq->quantity*$rfq->Price }}.00/-</b>
                            </h2>
                        </div>
                        <div class="row no-gutters mt-4">
                            <div class="col-sm-2">
                                <div class="opacity-50 my-2">{{ translate('Share')}}:</div>
                            </div>
                            <div class="col-sm-10">
                                <div class="aiz-share"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

当我运行127.0.0.1:8080/inforfq/1 时,这会将我重定向到登录页面。

我如何从127.0.0.1:8080/inforfq/1 中删除身份验证系统。

【问题讨论】:

  • 很多代码......你的“路线”代码是什么?
  • 请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example

标签: php laravel authentication controller laravel-8


【解决方案1】:

您需要删除网络中间件, 检查您的路线文件是否有类似的内容:

Route::group(['middleware' => ['web']

或:

Route::get('')->middleware('web');

移除web中间件或将路由移到组外

你还应该检查RouteServiceProvider,中间件可以在这里定义,cf:

https://github.com/laravel/laravel/blob/8.x/app/Providers/RouteServiceProvider.php

如果是这样的话:

Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

改为:

Route::namespace($this->namespace)
     ->group(base_path('routes/web.php'));

请注意,现在默认情况下不会包含 Web 中间件,因此您应该为所有经过身份验证的路由添加带有该中间件的路由组:

Route::group(['middleware' => ['web']], function() {
// all your previously authenticated routes goes here
});
// everything else is not authenticated by web middlware

如果您有很多这样的路由,最好创建一个 routes/public.php 并将其添加到您的提供商:

Route::namespace($this->namespace)
     ->group(base_path('routes/public.php'));

这样你就不必从 routes/web.php 中删除 web 中间件,它更干净,避免错误,因为很容易忘记 web.php 不再有 web 中间件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多