• Categories
  • app/Helpers/helpers.php

    Line no. 639 –
    [php]
    function categories($orderByField,$orderBy,$limit) {
    $categories = Category::orderBy($orderByField,$orderBy)->limit($limit)->get();
    return $categories;
    }

    resources/views/website/footer.blade.php
    Line no. 33 –

    @php $categories = categories(‘id’,’ASC’,10); @endphp
    @foreach($categories as $category)
    <li><a href="{{ url(‘/shopproductsbycategory?id=’.$category->id) }}">
    {{ $category->name }}
    </a></li>
    @endforeach
    [/php]

    404 Custom Page

    app/Exceptions/Handler.php
    Line no. 57 –
    [php]
    return response()->view(‘errors.404’);
    [php]
    changed file – resources/views/errors/404.blade.php

    Store Register

    app/Http/Controllers/Auth/StoreRegisterController.php
    Line no. 96 –
    [php]
    $user->assignRole(‘manager’);

    Line no. 109 –

    auth()->login($user);
    return redirect(‘dashboard’);
    [/php]

    Multiple Product Delete

    routes/web.php
    Line no. 253 –
    [php]
    Route::post(‘products/delete’, ‘ProductController@deleteMultiple’);

    [/php]
    app/Http/Controllers/ProductController.php
    Line no. 247 –
    [php]
    public function deleteMultiple(Request $request)
    {
    if (!env(‘APP_DEMO’, false)) {
    $this->productRepository->pushCriteria(new ProductsOfUserCriteria(auth()->id()));

    $productIds = explode(‘,’,$request->selected_product_ids);

    foreach($productIds as $id) {
    $product = $this->productRepository->findWithoutFail($id);

    if (empty($product)) {
    Flash::error(‘Product not found’);

    return redirect(route(‘products.index’));
    }

    $this->productRepository->delete($id);
    }

    Flash::success(__(‘lang.deleted_successfully’, [‘operator’ => __(‘lang.product’)]));

    } else {
    Flash::warning(‘This is only demo app you can\’t change this section ‘);
    }
    return redirect(route(‘products.index’));
    }

    [/php]
    app/DataTables/ProductDataTable.php
    Line no. 37 –
    [php]
    ->addColumn(‘select_all’, function ($product) {
    return ‘<input type="checkbox" name="product_id_checkbox" value="’.$product->id.’">’;
    })

    Line no. 125 –

    [
    ‘data’ => ‘select_all’,
    ‘title’ => ‘<input type="checkbox" name="select_all">’,
    ‘searchable’ => false, ‘orderable’ => false, ‘exportable’ => false, ‘printable’ => false
    ],

    [/php]
    resources/views/products/index.blade.php
    Line no. 30 –

    [php]
    @can(‘products.destroy’)
    <form method="POST" action="{{ url(‘/products/delete’) }}" accept-charset="UTF-8" class="delete_selected_form">
    {{ csrf_field() }}
    <input type="hidden" name="selected_product_ids">
    <button type="button" class="btn btn-link text-danger delete_products" data-toggle="tooltip" data-placement="right" title="Delete Selected Products">
    <i class="fa fa-trash fa-lg"></i>
    </button>
    </form>
    @endcan
    [/php]

    resources/views/products/table.blade.php
    Line no. 10 –
    [php]
    <script>
    $(document).on(‘click’, ‘[name="select_all"]’, function() {
    if ($(this).prop(‘checked’) == true) {
    $(‘[name="product_id_checkbox"]’).prop(‘checked’, true);
    } else {
    $(‘[name="product_id_checkbox"]’).prop(‘checked’, false);
    }
    });

    $(document).on(‘click’, ‘.delete_products’, function() {
    var product_ids = [];
    var i = 0;
    $(‘[name="product_id_checkbox"]:checkbox:checked’).each(function(e) {
    product_ids[i] = $(this).val();
    i++;
    });

    $(‘[name="selected_product_ids"]’).val(product_ids);

    if(product_ids.length == 0) {
    alert(‘Please select atleast one product’);
    } else {
    if(confirm(‘All selected products will be deleted. Are you sure?’)) {
    $(‘.delete_selected_form’).submit();
    }
    }
    })
    </script>
    [/php]

    ————————————————————————————————————————

    Multiple Driver Enable

    resources/views/layouts/right_toolbar.blade.php
    Line no. 26 –
    [php]
    @if($item->data == ‘checkbox’)
    @php continue; @endphp
    @endif

    [/php]

    routes/web.php
    Line no. 297 –
    [php]
    Route::post(‘drivers/enable’, ‘DriverController@enableMultipleDrivers’);

    [/php]

    app/Http/Controllers/DriverController.php
    Line no. 219 –
    [php]
    public function enableMultipleDrivers(Request $request)
    {
    $input = $request->all();
    $driver_ids = explode(‘,’,$input[‘selected_driver_ids’]);

    try {
    $this->driverRepository->enableMultipleDrivers($driver_ids);
    } catch (ValidatorException $e) {
    Flash::error($e->getMessage());
    }

    Flash::success(__(‘lang.updated_successfully’,[‘operator’ => __(‘lang.driver’)]));

    return redirect(route(‘drivers.index’));
    }
    [/php]

    app/Repositories/DriverRepository.php
    Line no. 39 –
    [php]
    public function enableMultipleDrivers($ids) {

    return DB::table(‘drivers’)->whereIn(‘id’,$ids)->update([‘available’ => 1]);
    }
    [/php]

    app/DataTables/DriverDataTable.php
    Line no. 30 –
    [php]
    ->addColumn(‘checkbox’, function ($driver) {
    if($driver->available == 0) {
    return ‘<input type="checkbox" name="driver_id_checkbox" value="’.$driver->id.’">’;
    } else {
    return ”;
    }
    })
    ->editColumn(‘user.name’, function ($driver) {
    return ‘<a href="’.url(‘users/’.$driver->user[‘id’].’/edit’).’" class="text-bold text-dark">’.$driver->user[‘name’].'</a>’;
    })

    [/php]

    Line no. 67 –
    [php]
    [
    ‘data’ => ‘checkbox’,
    ‘title’ => ‘<input type="checkbox" name="select_all">’,
    ‘searchable’ => false, ‘orderable’ => false, ‘exportable’ => false, ‘printable’ => false
    ],

    [/php]

    resources/views/drivers/index.blade.php
    Line no. 30 –

    [php]
    @can(‘drivers.edit’)
    <form method="POST" action="{{ url(‘/drivers/enable’) }}" accept-charset="UTF-8" class="enable_selected_form">
    {{ csrf_field() }}
    <input type="hidden" name="selected_driver_ids">
    <button type="button" class="btn btn-link text-success enable_drivers" data-toggle="tooltip" data-placement="right" title="Enable Selected Drivers">
    <i class="fa fa-check fa-lg"></i>
    </button>
    </form>
    @endcan
    [/php]

    resources/views/drivers/table.blade.php
    Line no. 10 –
    [php]
    <script>
    $(document).on(‘click’, ‘[name="select_all"]’, function() {
    if ($(this).prop(‘checked’) == true) {
    $(‘[name="driver_id_checkbox"]’).prop(‘checked’, true);
    } else {
    $(‘[name="driver_id_checkbox"]’).prop(‘checked’, false);
    }
    });

    $(document).on(‘click’, ‘.enable_drivers’, function() {
    var product_ids = [];
    var i = 0;
    $(‘[name="driver_id_checkbox"]:checkbox:checked’).each(function(e) {
    product_ids[i] = $(this).val();
    i++;
    });

    $(‘[name="selected_driver_ids"]’).val(product_ids);

    if(product_ids.length == 0) {
    alert(‘Please select atleast one product’);
    } else {
    if(confirm(‘All selected drivers will be available. Are you sure?’)) {
    $(‘.enable_selected_form’).submit();
    }
    }
    })
    </script>

    [/php]