vendredi 8 mai 2020

Query string on laravel URL route

So I have the following route configured that when I visit URL/employees/import it works great and the functionality does what I need it to do:

Route::get('employees/import', [
    'as' => 'employees.import',
    'uses' => 'EmployeesController@import'
]);

Here is the EmployeesController class:

class EmployeesController extends Controller
{
    protected $employeeImporter;

    public function __construct(EmployeeImporter $employeeImporter)
    {
        $this->middleware('auth', ['except' => ['import']]);
        $this->employeeImporter = $employeeImporter;
    }

    public function index()
    {
        $employees = Employee::all();

        return view('employees.index', compact('employees'));
    }

    public function show(Employee $employee)
    {
        return view('employees.show', compact('employee'));
    }

    public function update(EmployeeRequest $request, Employee $employee)
    {
        $employee->update($request->all());

        if (count($request->files) > 0) {
            $employee->touch();
        }

        return redirect()->route('employees.show', $employee->id);
    }

    public function import()
    {
        $this->employeeImporter->import();
    }
}

What I'm attempting to achieve:

So since the default call is employees/import - How can I make it be based on a query string? So I'd like the default to be employees/import?mode=update, but also have the option to have employees/import?mode=refresh that depends on another method inside the class?

All help would be appreciated! Learning and new to Laravel.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire