L
L
lynnikvadim2015-07-15 16:00:27
Laravel
lynnikvadim, 2015-07-15 16:00:27

Laravel 5 not deleting entry?

What am I doing wrong ?
My routes.php

<?php


Route::get('/', '[email protected]');

Route::get('home', '[email protected]');

Route::controllers([
  'auth' => 'Auth\AuthController',
  'password' => 'Auth\PasswordController',
]);
Route::get('admin', ['uses' => 'admin\[email protected]', 'as' => 'admin','middleware' => 'auhtgust']);
Route::get('admin/user', ['uses' => 'admin\[email protected]', 'as' => 'admin']);
Route::resource('admin/user','admin\UserController');

My view (part of it):
@foreach ($user as $user)
                      <tr>
                        <td>{{$user->name}}</td>
                        <td>{{$user->email}}</td>
                        <td>{{$user->tel}}</td>
                        <td>
                        @if ($user->active)  
                          <a href="../../index.html"><i class="fa fa-check-square fa-lg"></i></a>
                             
                            @else
                                 <a href="../../index.html"><i class="fa fa-check-square-o fa-lg"></i></a>
                        @endif
                        </td>

                         
                        <td> 
                      
                        {!! HTML::linkAction('admin\[email protected]',  'Удалить' , ($user->id)) !!}
                        <a href="../../index/{{$user->id}}.html"><i class="fa fa-pencil-square-o fa-lg deystviya"></i></a>
                        <a href="../../index/{{$user->id}}.html"><i class="fa fa-external-link fa-lg deystviya"></i></a></td>
                      </tr>
                      @endforeach

My controller:
<?php namespace App\Http\Controllers\admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang;

class UserController extends Controller {

  /**
   * Display a listing of the resource.
   *
   * @return Response
   */
  public function index()
  {
    App::setLocale('en');
    $lang = Lang::get('messages.userlist');
     
    $user = User::all();

    return view ('admin.UserView', ['user'=>$user,'lang'=>$lang]);

  }

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

      return view ('admin.CreateUser');



    
  }

  /**
   * Store a newly created resource in storage.
   *
   * @return Response
   */
  public function store(User $UserModel, Request $request )
  {
    //dd($request->all());
    $UserModel->create($request->all());
    return redirect()->route('admin');

     }



 
  /**
   * Display the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function show($id)
  {
    //
  }

  /**
   * Show the form for editing the specified resource.
   *
   * @param  int  $id
   * @return Response
   */
  public function edit($id)
  {
    //
  }

  /**
   * Update the specified resource in storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function update($id)
  {
    //
  }

  /**
   * Remove the specified resource from storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function destroy($id)
  {
    User::find($id)->delete();
 
   
       
   
 
 
    return redirect('admin/user');
  }

}

Data output without problems.
But when I click on "Delete" - I go to the page ...../index.php/admin/user/8
And I see just a white screen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-07-15
@Denormalization

You need to send a DELETE request to /admin/user/8 then everything will work.
You need to hang a JS handler on this button, and use it to send a DELETE request.
There are several options:
1) Wrap the button in a form and submit it when clicked
2) Send an AJAX request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question