Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 使用软删除时无法删除_Authentication_Controller_Laravel 5.1_Soft Delete_Laravel Blade - Fatal编程技术网

Authentication 使用软删除时无法删除

Authentication 使用软删除时无法删除,authentication,controller,laravel-5.1,soft-delete,laravel-blade,Authentication,Controller,Laravel 5.1,Soft Delete,Laravel Blade,尝试softdelete,我还不明白代码的错误。每当我尝试删除时。它没有,它把那一页扔给了我 这是删除前的控制器确认页面: public function deleteView($id) { $company = Company::find($id); return view('company.show')->with('company', $company); } @extends('layouts.member') @sect

尝试softdelete,我还不明白代码的错误。每当我尝试删除时。它没有,它把那一页扔给了我

这是删除前的控制器确认页面:

public function deleteView($id)
    {
        $company = Company::find($id);
        return view('company.show')->with('company', $company);
    }
@extends('layouts.member')

    @section('content')
        {!! Form::open(array('action'=> array('CompanyController@destroy', $company->id, '_method'=>'delete'))) !!}
        {!! Form::token() !!}

            <p>{!! $company->companyname !!}</p>
            <p>{!! $company->companyaddress !!}</p>
            </p>{!! $company->country !!}</p>
            <p>{!! $company->state !!}</p>
            <p>{!! $company->email !!}</p>
            <p>{!! $company->phone !!}</p>
            <p>{!! $company->website !!}</p>
            <p>{!! $company->companytype !!}</p>

            {!! Form::hidden('company_id', $company->id) !!}
            <p>{!! Form::submit('DELETE') !!}</p>
        {!! Form::close() !!}
    @stop
public function destroy(CompanyRequest $companyRequest)
    {
        $company_id = $companyRequest->company_id;
        if(!$this->companyBelongsToUser($company_id))
        {
            return redirect()->route('companyindex', $company_id)->with('message', 'Sorry, yuo cannot delete this company');
        }else
        {
            $company = Company::findOrFail($company_id);
            $company->delete();

            return redirect()->route('companyindex', $company_id)->with('message', 'Company deleted successfully');
        }
    }
Route::get('delete/{id}', array('as'=>'deleteView', 'uses'=>'CompanyController@deleteView'));
Route::delete('deletecompany/{id}', array('as'=>'deleteCompany', 'uses'=>'CompanyController@destroy'));
这是删除前要确认的视图:

public function deleteView($id)
    {
        $company = Company::find($id);
        return view('company.show')->with('company', $company);
    }
@extends('layouts.member')

    @section('content')
        {!! Form::open(array('action'=> array('CompanyController@destroy', $company->id, '_method'=>'delete'))) !!}
        {!! Form::token() !!}

            <p>{!! $company->companyname !!}</p>
            <p>{!! $company->companyaddress !!}</p>
            </p>{!! $company->country !!}</p>
            <p>{!! $company->state !!}</p>
            <p>{!! $company->email !!}</p>
            <p>{!! $company->phone !!}</p>
            <p>{!! $company->website !!}</p>
            <p>{!! $company->companytype !!}</p>

            {!! Form::hidden('company_id', $company->id) !!}
            <p>{!! Form::submit('DELETE') !!}</p>
        {!! Form::close() !!}
    @stop
public function destroy(CompanyRequest $companyRequest)
    {
        $company_id = $companyRequest->company_id;
        if(!$this->companyBelongsToUser($company_id))
        {
            return redirect()->route('companyindex', $company_id)->with('message', 'Sorry, yuo cannot delete this company');
        }else
        {
            $company = Company::findOrFail($company_id);
            $company->delete();

            return redirect()->route('companyindex', $company_id)->with('message', 'Company deleted successfully');
        }
    }
Route::get('delete/{id}', array('as'=>'deleteView', 'uses'=>'CompanyController@deleteView'));
Route::delete('deletecompany/{id}', array('as'=>'deleteCompany', 'uses'=>'CompanyController@destroy'));
这是删除前返回确认页面的路径:

public function deleteView($id)
    {
        $company = Company::find($id);
        return view('company.show')->with('company', $company);
    }
@extends('layouts.member')

    @section('content')
        {!! Form::open(array('action'=> array('CompanyController@destroy', $company->id, '_method'=>'delete'))) !!}
        {!! Form::token() !!}

            <p>{!! $company->companyname !!}</p>
            <p>{!! $company->companyaddress !!}</p>
            </p>{!! $company->country !!}</p>
            <p>{!! $company->state !!}</p>
            <p>{!! $company->email !!}</p>
            <p>{!! $company->phone !!}</p>
            <p>{!! $company->website !!}</p>
            <p>{!! $company->companytype !!}</p>

            {!! Form::hidden('company_id', $company->id) !!}
            <p>{!! Form::submit('DELETE') !!}</p>
        {!! Form::close() !!}
    @stop
public function destroy(CompanyRequest $companyRequest)
    {
        $company_id = $companyRequest->company_id;
        if(!$this->companyBelongsToUser($company_id))
        {
            return redirect()->route('companyindex', $company_id)->with('message', 'Sorry, yuo cannot delete this company');
        }else
        {
            $company = Company::findOrFail($company_id);
            $company->delete();

            return redirect()->route('companyindex', $company_id)->with('message', 'Company deleted successfully');
        }
    }
Route::get('delete/{id}', array('as'=>'deleteView', 'uses'=>'CompanyController@deleteView'));
Route::delete('deletecompany/{id}', array('as'=>'deleteCompany', 'uses'=>'CompanyController@destroy'));
这是实际删除的路径:

public function deleteView($id)
    {
        $company = Company::find($id);
        return view('company.show')->with('company', $company);
    }
@extends('layouts.member')

    @section('content')
        {!! Form::open(array('action'=> array('CompanyController@destroy', $company->id, '_method'=>'delete'))) !!}
        {!! Form::token() !!}

            <p>{!! $company->companyname !!}</p>
            <p>{!! $company->companyaddress !!}</p>
            </p>{!! $company->country !!}</p>
            <p>{!! $company->state !!}</p>
            <p>{!! $company->email !!}</p>
            <p>{!! $company->phone !!}</p>
            <p>{!! $company->website !!}</p>
            <p>{!! $company->companytype !!}</p>

            {!! Form::hidden('company_id', $company->id) !!}
            <p>{!! Form::submit('DELETE') !!}</p>
        {!! Form::close() !!}
    @stop
public function destroy(CompanyRequest $companyRequest)
    {
        $company_id = $companyRequest->company_id;
        if(!$this->companyBelongsToUser($company_id))
        {
            return redirect()->route('companyindex', $company_id)->with('message', 'Sorry, yuo cannot delete this company');
        }else
        {
            $company = Company::findOrFail($company_id);
            $company->delete();

            return redirect()->route('companyindex', $company_id)->with('message', 'Company deleted successfully');
        }
    }
Route::get('delete/{id}', array('as'=>'deleteView', 'uses'=>'CompanyController@deleteView'));
Route::delete('deletecompany/{id}', array('as'=>'deleteCompany', 'uses'=>'CompanyController@destroy'));
此函数用于检查用户是否为预期用户

private function companyBelongsToUser($id){
        $company = Company::find($id);
        if($company->user_id == Auth::user()->id){
            return true;
        }
        return false;
    }

最后,我把它解决了。主要问题是,我试图在运行时检索公司的id,但该id不可用

令我惊讶的是,拉雷维尔已经关心我试图手动完成的事情,我所做的只是传入一个通用id,拉雷维尔发现了我想要查询的公司,并完成了这项工作

public function destroy($id)
    {
        $company = Company::findOrFail($id);
        if(!$company->user_id === Auth::user()->id)
        {
            return redirect()->route('companyindex')->with('message', 'Sorry, you cannot delete this company');
        }else{
            $company->delete();
            return redirect()->route('companyindex')->with('message', 'Company successfully deleted.');
        }
    }

你说的“把书页扔给我”是什么意思?您得到了什么错误?没有错误消息,只返回页面。