使用laravel返回的软删除方法[destroy]不存在

时间:2015-04-18 12:15:40

标签: php laravel-4 controller

我正在尝试从我的数据库中删除一行,但它不起作用...

所以我想做的是在用户进行身份验证后,他们可以管理几件事情。他们也能够“删除”东西。但实际上这是一个软删除。

我对视图的看法(称为index.blade.php):

<tbody>

                            @foreach($events as $event)
                            @if($event->expire <= time())
                            <tr class="danger">
                            @else
                            <tr>
                            @endif

                            <td>{{ $event->rally_name }}</td>

                            <td>{{ $event->short_info }}</td>

                            <td>
                                @if($event->is_podium == 'true')
                                <i class="fa fa-check" style="color:rgb(46, 204, 113);"></i>
                                @else
                                <i class="fa fa-close" style="color:rgb(192, 57, 43);"></i>
                                @endif
                            </td>

                            <td>
                                @if($event->is_radio == 'true')
                                <i class="fa fa-check" style="color:rgb(46, 204, 113);"></i>
                                @else
                                <i class="fa fa-close" style="color:rgb(192, 57, 43);"></i>
                                @endif
                            </td>

                            <td><a href="{{ $event->website }}" target="_blank">{{ $event->website }}</a></td>

                            <td>
                            @if($event->expire <= time())
                            <p>Verlopen.</p>
                            @else
                            {{ date('d/m/Y', $event->start_date) }} - {{ date('d/m/Y', $event->expire) }}
                            @endif
                            </td>

                            <td><a href="#" class="btn btn-sm yellow">Bewerken <i class="fa fa-edit"></i></a></td>

                            <td>
                            {{ Form::open(['method' => 'delete', 'route' => ['calendar.destroy', $event->id]]) }}
                                {{ Form::button('Verwijderen <i class="fa fa-trash-o"></i>', array('type' => 'submit', 'class' => 'btn btn-sm red')) }}
                            {{ Form::close() }}

                            </td>

                            </tr>
                            @endforeach

                            </tbody>

此视图存储在

  

应用程序/视图/管理/日历/ index.blade.php

它有效,但删除不...我的路由器是这样的:

Route::group(array('before' => 'auth'), function()
{
        Route::resource('admin', 'AdminController');
        Route::resource('admin/news/create', 'AdminNewsController');
        //events
        Route::resource('admin/calendar/index', 'AdminCalendarController');
        Route::resource('admin/calendar/create', 'AdminCalendarController');
});

我认为可以在我的路由器中调用admin/calendar吗?但我不知道这是否可能......

但好吧......

我的AdminCalendarController.php看起来像这样:

<?php

class AdminCalendarController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $select_events = DB::table('event')->orderBy('expire', 'DESC')->whereNull('deleted_at')->get();

        foreach ($select_events as $events) {

            $events = array();
        }


        return View::make('admin.calendar.index')->with('events', $select_events);
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        return View::make('admin.calendar.create');
    }


    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        //
    }


    /**
     * 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)
    {
        // delete
        $calendar = Calendar::find($id);
        $calendar->delete();

        // redirect
        Session::flash('message', 'Successfully deleted the thing!');
        return Redirect::to(Config::get('app.url').'/admin/calendar/index');
    }


}

最后,Calendar.php

<?php

use Illuminate\Database\Eloquent\SoftDeletingTrait;

class Calendar extends Eloquent {

    protected $table = 'event';
    public $timestamps = false;

    use SoftDeletingTrait;

    protected $dates = ['deleted_at'];

}

我的数据库如下所示:

database model

当我尝试执行'删除'时,它唯一能做到以下几点:

error

此外,该网址会删除admin部分。

感谢您的帮助!

最诚挚的问候,

2 个答案:

答案 0 :(得分:1)

你的路由器看起来非常错误。

它应该是这样的:

Route::group(array('before' => 'auth', 'prefix' => 'admin'), function()
{
        Route::resource('news', 'AdminNewsController');
        Route::resource('calendar', 'AdminCalendarController');
});

答案 1 :(得分:1)

我发现问题,这是URL,在查看源代码后,我看到URL中没有admin,所以现在它已经修复了。 :d