-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method save return 404 when there is a parameter id in the url #2216
Comments
My route list : |
<?php
declare(strict_types=1);
namespace App\Orchid\Screens\Accounts\Company;
use App\Models\Account;
use App\Models\Company;
use App\Orchid\Layouts\Account\AccountEditLayout;
use App\Orchid\Layouts\Account\Company\CompanyEditLayout;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Orchid\Screen\Action;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;
use Orchid\Support\Facades\Layout;
use Orchid\Support\Facades\Toast;
class CompanyEditScreen extends Screen
{
/**
* @var Account
*/
public $account;
/**
* @var Company
*/
public $company;
/**
* Query data.
* @param Company $company
*
* @return array
*/
public function query(Account $account, Company $company): iterable
{
return [
'account' => $account,
'company' => $company,
];
}
/**
* Display header name.
*
* @return string|null
*/
public function name(): ?string
{
return $this->company->exists ? 'Modifier une entreprise' : 'Créer une entreprise';
}
/**
* Display header description.
*
* @return string|null
*/
public function description(): ?string
{
return $this->company->exists ? "Modifier l'entreprise de ".$this->company->account->name : 'Créer une entreprise';
}
/**
* @return iterable|null
*/
public function permission(): ?iterable
{
return [
'platform.gestion.accounts',
];
}
/**
* Button commands.
*
* @return Action[]
*/
public function commandBar(): iterable
{
return [
Button::make(__('Supprimer'))
->icon('trash')
->confirm(__('Êtes-vous sur de vouloir supprimer ce compte ? Toutes les données liées seront également supprimées.'))
->method('remove')
->canSee($this->company->exists),
Button::make(__('Sauvegarder'))
->icon('check')
->method('save'),
];
}
/**
* @return \Orchid\Screen\Layout[]
*/
public function layout(): iterable
{
$layout_top = [];
$layout_bottom = [];
if ($this->company->id !== null)
{
$layout_top = [
];
$layout_bottom = [
];
}
return [
...$layout_top,
Layout::block(CompanyEditLayout::class)
->title(__('Entreprise'))
->description(__('Informations de l\'entreprise')),
...$layout_bottom,
];
}
public function save(Request $request)
{
$request->validate([
'company.name' => [
'required',
],
/*'company.logo' => [
'required',
],*/
]);
$companyData = $request->get('company');
$companyData['account_id'] = $this->account->id;
$companyData['logo'] = 'ok';
$company = new Company();
$company
->fill($companyData)
->save();
Toast::info(__('Entreprise mis à jour avec succès.'));
return redirect()->route('platform.gestion.accounts.edit', $company->account->id);
}
/**
* @param Company $company
*
* @throws \Exception
*
* @return \Illuminate\Http\RedirectResponse
*
*/
public function remove(Company $company)
{
$company->delete();
Toast::info(__('Company was deleted.'));
return redirect()->route('platform.gestion.accounts.edit', $company->account->id);
}
} for method save , if push two parameters like this public function save(Company $company, Request $request) or public function save(Account $account, Request $request) i get a error 404 but public function save(Request $request) i can process my save method but i need $company and $account .. I don't know how to accomplish that... |
I have the same issue, after some digging through the screen flow of Orchid I found the following in src/Screen/Screen.php:197 /**
* @param mixed ...$parameters
*
* @throws Throwable
*
* @return Factory|View|\Illuminate\View\View|mixed
*/
public function handle(...$parameters)
{
Dashboard::setCurrentScreen($this);
abort_unless($this->checkAccess(), 403);
if (request()->isMethod('GET')) {
return $this->redirectOnGetMethodCallOrShowView($parameters);
}
$method = Route::current()->parameter('method', Arr::last($parameters));
$prepare = collect($parameters)
->merge(request()->query())
->diffAssoc($method)
->all();
return $this->callMethod($method, $prepare) ?? back();
} The handle function uses diffAssoc to remove the method (save in our case) from the parameters. But this only works if method is the first in the parameter collection. So if you have a parent in the parameters it does not remove the method. Then the method gets picked up as an identifier for your object, resulting in a 404 because there is no object with ID 'save'. Replacing diffAssoc with just diff seems to work for me, but I don't know if that would break other cases. edit: format |
any workaround with this @tabuna ? more than one params? |
Any updates for this issue? |
My issue was that I wanted to use a "create or update" method, which caused me to get a 404. So I guess I was having an altogether different issue. |
same error...😢 |
The problem was resolved when updated Larvel |
Hi @danvirsen, I had a problem even passing one parameter. I've been following this article https://orchid.software/en/docs/quickstart-crud/ If you do everything as indicated, "editing" will work, but there will be a problem when "creating" - 404 (route not found). I changed the $post variable to $post and was able to "create", but an error occurred - 404 when "editing". I will be glad if you share your experience or advice. Thanks |
https://github.com/orchidsoftware/platform/blob/master/stubs/app/routes/platform.php I solved this issue by using the same route format for the default modules User and Role, in the stubs files appears with, a creation route, an editing route and a listing route, you need to be careful with the required parameters and not required parameters because maybe return an unexpected message. That works like a charm for me. |
Describe the bug
When we have a parameter in the url like an idenifiant for example a route like this
https://www.laravel.local/admin/accounts/1/company/add
i got error 404 when i tried to save
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I have two tables, account and companies, in the account area, we can modify the account information and add companies, I have a 404 error just after I try to add a company
Screenshots
https://ibb.co/5Y8Gfdb
https://ibb.co/1XnQzfK
The text was updated successfully, but these errors were encountered: