dimanche 24 novembre 2019

laravel trashed method does not exist

I'm on the project in which I want to get the table in which record which I was trashed show and its working correctly and my trashed records are also show.

My logic of code is that when my trashed record are shown then in action field it show me only restore button otherwise in that field it show me two button of 'Delete' and 'Trash'. for this to work, when I apply this condition in my view file its return me this error which written in my title. @if($record->trashed())

resource controller

namespace App\Http\Controllers;

use App\sepCategory; use Illuminate\Http\Request;

class SepCategoryController extends Controller {
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $cat=sepCategory::all();
        return view('cusCate',compact('cat'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\sepCategory  $sepCategory
     * @return \Illuminate\Http\Response
     */
    public function show(sepCategory $sepCategory)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\sepCategory  $sepCategory
     * @return \Illuminate\Http\Response
     */
    public function edit(sepCategory $sepCategory , $id)
    {

        $a= sepCategory::find($id);

       return  view('cusEdit',['data'=>$a]);

    }    

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\sepCategory  $sepCategory
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, sepCategory $sepCategory)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\sepCategory  $sepCategory
     * @return \Illuminate\Http\Response
     */
    public function destroy(sepCategory $sepCategory,$id)
    {
          if ($sepCategory::find($id)->forceDelete()) {
                return back()->with('message','record successfully delete');
          } else {
            return back()->with('error','record not delete');
          }





    }
    public function trash()
    {
         $cat=sepCategory::onlyTrashed()->paginate(3);
         return view('cusCate',compact('cat'));
    }

    public function remove($id)
    {
       $temp= sepCategory::find($id);
       if ($temp->delete()) {
           return back()->with('message','record successfully trashed');

       }else{
           return back()->with('error','can not correctly trashed');
       }
    }

    public function recover($id)
    {

    } }

view blade file

 <a href="" class="btn-success">view the trashed data</a>


Category of student

   @if(session()->has('message'))
     <div class="alert alert-success">
      
      </div>
  @elseif(session()->has('error'))
      <div class="alert alert-danger">
     
      </div>
  @else
  @endif
  <table>
  <tr>
    <th>Name</th>
    <th>id</th>
    <th>Phone</th>
    <th>Roll no</th>
    <th>Action</th>
    <th>
         @if ($cat->trashed())
         Deleted At
         @else
        updated At
         @endif
        </th>
</tr>




@if (isset($cat))


@foreach ($cat as $item)
<tr>


    <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td>


    @if ($item->trashed())
        <a href="" class="btn btn-success">Restore</a>
    @else

        <a href="" class="btn btn-success">Edit</a>

        <form action="" method="post">
          @csrf
          
          <input type="hidden" value="" name="id">
          <button type="submit">Delete</button>
        </form>



       <!-- this is trashed-->
       <a href="" class="btn btn-primary">Trashed</a>
    @endif


        </td>




        <td>
                @if ($item->trashed())
                      
                @else
                      
                @endif

        </td>






</tr>
@endforeach

  @endif

Error

Method Illuminate\Database\Eloquent\Collection::trashed does not exist. (View: D:\xamp\htdocs\project laravel\newTran\resources\views\cusCate.blade.php)

why it say trashed not exist



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ODQcex
via IFTTT

Aucun commentaire:

Enregistrer un commentaire