lilo
2 weeks ago
234
7
Laravel

Connection: null problem

Posted 2 weeks ago by lilo

Hi,

In my panel, when I try to edit, show or delete some data I get this error:

Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameters for [Route: admin.excuses.update] [URI: admin/excuses/{excus}]. (View: C:\Users.....\resources\views\admin\excuses\edit.blade.php)

When I dump and die it, it shows that connection is null but in other cruds, there isn't this problem. In others, connection is set as mysql. Also when I try to create new "excuse" entry, it is successfully saved in database. But I cannot retrieve these data.

So, I didn't really understand why in only this "excuse" crud there is connection problem.

Here is my excuse controller:

class ExcuseController extends Controller

{

public function index(Request $request) { abort_if(Gate::denies('excuse_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

    if ($request->ajax()) {
        $query = Excuse::with(['user', 'created_by'])->select(sprintf('%s.*', (new Excuse)->table));
        $table = Datatables::of($query);

        $table->addColumn('placeholder', ' ');
        $table->addColumn('actions', ' ');

        $table->editColumn('actions', function ($row) {
            $viewGate      = 'excuse_show';
            $editGate      = 'excuse_edit';
            $deleteGate    = 'excuse_delete';
            $crudRoutePart = 'excuses';

            return view('partials.datatablesActions', compact(
                'viewGate',
                'editGate',
                'deleteGate',
                'crudRoutePart',
                'row'
            ));
        });

        $table->editColumn('id', function ($row) {
            return $row->id ? $row->id : "";
        });
        $table->addColumn('user_name', function ($row) {
            return $row->user ? $row->user->name : '';
        });

        $table->rawColumns(['actions', 'placeholder', 'user']);

        return $table->make(true);
    }

    $users = User::get();
    $users = User::get();

    return view('admin.excuses.index', compact('users', 'users'));
}

public function create()
{
    abort_if(Gate::denies('excuse_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

    $users = User::all()->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

    return view('admin.excuses.create', compact('users'));
}

public function store(StoreExcuseRequest $request)
{
    $excuse = Excuse::create($request->all());

    $excuses = Excuse::with('user')->get();
    $users = User::whereIn('id', $excuses->pluck('user_id'))->get();
    $grouped = $excuses->groupBy('user_id');
    $sums = $grouped->map->sum(function($excuse) {
        $start = $excuse->start_date;
        $end =$excuse->end_date;
        return Carbon::parse($start)->diffInDays($end,false);
    });

    foreach ($users as $user) {
        $user->remaining_permit = $user->excuse_count - $sums[$user->id];
        $user->save();
    }

    return redirect()->route('admin.excuses.index');
}

public function edit(Excuse $excuse)
{
    abort_if(Gate::denies('excuse_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

    $users = User::all()->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

    $excuse->load('user', 'created_by');

    return view('admin.excuses.edit', compact('users', 'excuse'));
}

public function update(UpdateExcuseRequest $request, Excuse $excuse)
{
    $excuse->update($request->all());

    return redirect()->route('admin.excuses.index');
}

public function show(Excuse $excuse)
{
    abort_if(Gate::denies('excuse_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

    $excuse->load('user', 'created_by');

    return view('admin.excuses.show', compact('excuse'));
}

public function destroy(Excuse $excuse)
{
    abort_if(Gate::denies('excuse_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

    $excuse->delete();

    return back();
}

public function massDestroy(MassDestroyExcuseRequest $request)
{
    Excuse::whereIn('id', request('ids'))->delete();

    return response(null, Response::HTTP_NO_CONTENT);
}

}

How can I solve this problem? Thank you in advance!

Please sign in or create an account to participate in this conversation.