micky
micky

Reputation: 317

laravel 5 routing error

the error is:

Route [users.destroy,$user->id] not defined. (View: C:\xampp\htdocs\laravel\resources\views\users\index.blade.php)

in index.blade.php

@section('main')

<h1>All Users</h1>

<p><a href={!! url('users\create') !!}>Add new user</a></p>

@if ($users->count())
    <table border="2">
<tr><td>s.n.</td><td>name</td><td>email</td><td>options</td>
            @foreach ($users as $user)
           <tr>
<td>{{ $user->id }}</td>
        <td>{{ $user->name }}</td>
    <td>{!! $user->email !!}</td>
                    <td><a href={!! url('users\edit\{id}', $user->id) !!}>Edit</a></td>
                  <td><a href={!! url('users\delete\{id}', $user->id) !!}>Delete</a></td>

<td>
          {!! Form::open(array('method' => 'DELETE', 
        'route' => array('users.destroy,$user->id'))) !!}                       
                            {!! Form::submit('Delete', array('class' => 'btn btn-danger')) !!}
                        {!! Form::close() !!}
                    </td>                
</tr>
      @endforeach


    </table>
@else
    There are no users
@endif

@stop

and the controller is:

<?php



namespace App\Http\Controllers;


use Illuminate\Http\Request;


use App\Http\Requests;

use App\Http\Controllers\Controller;


use App\User;

class UserController extends Controller

{

  public function index()
  {

    $users=User::all();
    return view('users.index', compact('users'));
  }

  public function create()
  {
    return View('users.create');
  }

  public function store()
  {

        $input = Input::all();
        $validation = Validator::make($input, User::$rules);

        if ($validation->passes())
        {
            User::create($input);

            return Redirect::route('users.index');
        }

        return Redirect::route('users.create')
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors.');
  }

  public function show($id)
  {
    //
  }
  public function edit($id)
  {
  $user = User::find($id);
        if (is_null($user))
        {
            return Redirect::route('users.index');
        }
        return View('users.edit', compact('user'));
  }

  public function update($id)
  {
    $input = Input::all();
        $validation = Validator::make($input, User::$rules);
        if ($validation->passes())
        {
            $user = User::find($id);
            $user->update($input);
            return Redirect::route('users.show', $id);
        }
return Redirect::route('users.edit', $id)
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors.');
  }
  public function destroy($id)
  {
    User::find($id)->delete();
        return Redirect::route('users.index');
  }

}

and when i delete the form in view file index.blade.php the white blank page appears. earlier i didnot install html entities and it worked well except for the part of form.

Upvotes: 0

Views: 1562

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Use this:

'route' => array('users.destroy', $user->id)

Then make sure you have users.destroy route in your routes.php file.

Upvotes: 1

Related Questions