andrews-quest liked a comment+100 XP
2mos ago
I don't use React, so I'm not sure about your situation. However, I pass parameters in the Route() method, using named routes. I also use inertia's useForm().
So my call might look something like:
my_form.put( route( 'calls.edit', { 'param1': value1, 'param2': value2 } ) );
Inertia's useForm() is pretty helpful and route() makes the code cleaner. I don't use the method or action attributes in forms anymore. For more info, see the 'Form Helper' section in the docs:
Note the Inertia route() is slightly different than the Laravel version, because it passes the params as an object rather than an array.
Also, fwiw, I only use post, put or delete on forms.
Inertia's useForm() makes form handling fairly straightforward for most situations, and you can fall back to axios (included), if it's needed.
HTH,
andrews-quest wrote a reply+100 XP
2mos ago
andrews-quest started a new conversation+100 XP
2mos ago
I'm trying to use Inertia <Form> to pass some parameters to a URL request, along some other ones that are stored as variables in React.
For that I'm trying to use object merging like:
<Form
method='GET'
action='/calls'
transform={data => ({...queryParams, ...data})}
>
But that flops because, for some reason, the form's URL parameters always get overwritten by whatever other parameters I have stored in queryParams.
Another problem would be that all the Parameters gets put into the URL, even if they are empty.
Is there an elegant solution? Is my approach beneficial at all?
andrews-quest wrote a reply+100 XP
5mos ago
andrews-quest started a new conversation+100 XP
5mos ago
Hi, when building with Vite I get the following message:
error during build: [@laravel/vite-plugin-wayfinder] [plugin @laravel/vite-plugin-wayfinder] Error generating types: Error: Command failed: php artisan wayfinder:generate --with-form
And that's only at the dev server. When I try the same on the release, everything runs smooth.
I've tried comparing the composer.lock files on the remote and the dev, but they are identical as expected.
andrews-quest wrote a reply+100 XP
6mos ago
andrews-quest wrote a reply+100 XP
6mos ago
andrews-quest liked a comment+100 XP
6mos ago
Hi, I have a bunch of calls, which I need to return sorted by different columns (/calls/datetime, /calls/operator etc.).
What'd be the correct approach in this scenario? Should the index() function of the CallController capture the URL parameter and base its output based on that? Should it be split into multiple functions?
@andrews-quest You would use a query string parameter here to control how you want records sorting, i.e.
/calls?sort=datetime/calls?sort=operator
You can use Spatie’s Laravel Query Builder package as mentioned by @glukinho to implement sorting (https://spatie.be/docs/laravel-query-builder/v6/features/sorting):
class CallController extends Controller
{
public function index()
{
$calls = QueryBuilder::for(Call::query())
->allowedSorts([
'datetime',
'operator',
// Any other column you want to be able to sort by...
])
->paginate();
return view('calls.index', compact('calls'));
}
}
andrews-quest wrote a reply+100 XP
6mos ago
andrews-quest wrote a reply+100 XP
6mos ago