4

I'm using yajra/laravel-datatables-buttons and I can't find a doc useful enough to help me.

I'm using the create button from the package which looks like this:

enter image description here

It should redirect me to my route which is: http://laravel.blog/admin/posts/create

But it keeps on redirecting me to http://laravel.blog/admin/posts/creer

it translates 'create' into 'creer' and I have no idea why it would do that. I'm building the app in english only and never used french for routes or anything.

AdminPostsDatatable.php:

/**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->setTableId('adminpostsdatatable-table')
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->dom('Bfrtip')
                    ->orderBy(1, 'desc')
                    ->buttons(
                        Button::make('create'),
                        Button::make('export'),
                        Button::make('print'),
                        Button::make('reset'),
                        Button::make('reload')
                    );
    }

admin.posts.index view:

@extends("layouts.app")

@section('content')

    <h1>Posts</h1>
    @if (session('status'))
        <div class="alert alert-success">
            {{ session('status') }}
        </div>
    @endif
    {!! $dataTable->table() !!}
@endsection

@push('scripts')
    {!! $dataTable->scripts() !!}
@endpush

routes:

|        | GET|HEAD  | admin                         | admin.                | Closure                                                                | web,auth                                             |
|        | POST      | admin/posts                   | admin.posts.store     | App\Http\Controllers\AdminPostsController@store                        | web,auth                                             |
|        | GET|HEAD  | admin/posts                   | admin.posts.index     | App\Http\Controllers\AdminPostsController@index                        | web,auth                                             |
|        | GET|HEAD  | admin/posts/create            | admin.posts.create    | App\Http\Controllers\AdminPostsController@create                       | web,auth                                             |
|        | PUT|PATCH | admin/posts/{post}            | admin.posts.update    | App\Http\Controllers\AdminPostsController@update                       | web,auth                                             |
|        | DELETE    | admin/posts/{post}            | admin.posts.destroy   | App\Http\Controllers\AdminPostsController@destroy                      | web,auth                                             |
|        | GET|HEAD  | admin/posts/{post}/edit       | admin.posts.edit      | App\Http\Controllers\AdminPostsController@edit                         | web,auth           

Thanks in advance.

2 Answers 2

6

I dont really know if it's the right way to do it but I've come up with this solution:

Button::make('create')->action("window.location = '".route('admin.posts.create')."';"),
Sign up to request clarification or add additional context in comments.

1 Comment

Why should we add window.location? Is there another option?
1

Try this

         public function html()
            {
                return $this->builder()
                            ->setTableId('adminpostsdatatable-table')
                            ->columns($this->getColumns())
                            ->minifiedAjax()
                            ->dom('Bfrtip')
                            ->orderBy(1, 'desc')   
                            ->parameters([
                            'buttons'      => 
                             [
                                [
                                    'text' =>'<i class="fa fa-eye"></i> ' . 'My custom button',
                                    'className' => 'My custom class'
                                ],
                                 'csv',
                                 'excel'
                             ],
                              ]);
            }

and if you want dropdown collection button

                        'buttons'      => 
                           [
                             "extend"=> 'collection',
                             "text"=> 'My Collection button',
                             "buttons" => 
                                 [ 
                                   'csv',
                                   'excel',
                                    [                
                                        [
                                           'text' =>'<i class="fa fa-eye"></i> ' . 'My custom button',
                                           'className' => 'My custom class'
                                        ],
                                     ] 
                                 ]
                           ],

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.