Laravel - The POST method is not supported for this route. Supported methods: GET, HEAD
this is my laravel orchid screen
\<?php
namespace App\Orchid\Screens\Examples;
use App\Models\Contact;
use Illuminate\Http\Request;
use App\Models\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Mail;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Quill;
use Orchid\Screen\Fields\Relation;
use Orchid\Screen\Fields\Textarea;
use Orchid\Support\Facades\Layout;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;
use Orchid\Support\Facades\Alert;
class ExampleFieldsAdvancedScreen extends Screen
{
/**
* Query data.
*
* @return array
*/
public function query(): iterable
{
return [
];
}
/**
* Display header name.
*
* @return string|null
*/
public function name(): ?string
{
return 'Bulk Add or Bulk Send';
}
/**
* Display header description.
*
* @return string|null
*/
public function description(): ?string
{
return 'Upload contact csv or create new.';
}
/**
* Button commands.
*
* @return Action[]
*/
public function commandBar(): iterable
{
return [
Button::make('Upload')
->method('POST')
->icon('paper-plane')
];
}
//upload the csv file
public function Upload(Request $request)
{
request()->validate([
'users' => 'required|mimes:xlx,xls|max:2048'
]);
$attachment = $file->load();
Excel::import(new ContactImport, $request->file('users'));
return back()->with('massage', 'User Imported Successfully');
}
/**
* Views.
*
* @throws \Throwable
*
* @return \Orchid\Screen\Layout[]
*/
public function layout(): iterable
{
return [
Layout::rows([
Input::make('users')
->type('file')
->title('Upload one csv file')
->horizontal(),
Relation::make('contacts.')
->title('recipients')
->multiple()
->required()
->placeholder('Mobile Number')
->help('Enter the users that you would like to send this message to.')
->fromModel(Contact::class,'name','mobile'),
TextArea::make('post.description')
->title('Enter the message you want to send')
->rows(3)
->maxlength(200)
->placeholder('Currently Flex is Down'),
Button::make('Send Message')
->method('sendMessage')
->icon('paper-plane')
])->title('Contacts upload'),
];
}
}
Very little context for this error @farirai - what action do you take to cause the error message?
Aside; this method method is not expecting a HTTP verb AFAIK, but a method in the same class:
Button::make('Upload')
->method('POST')
->icon('paper-plane')
@tykus i tried changing the button method to post but still getting the same error
want i am trying to do when i get the error is to upload csv file to local storage
you can read "Extra >> Controllers" section of official Orchid docs and transform example code to define route:
use App\Orchid\Screens\UploadScreen;
Route::post('/upload/load', [UploadScreen::class, 'load']);
somewhere in platform.php file. Your route will be /admin/upload/load and method is POST.
also update your Screen
/** The screen's action buttons.
*
* @return \Orchid\Screen\Action[]
*/
public function commandBar(): iterable
{
return [
Button::make("Send")
->action(
route('platform.upload', [
'method' => 'load',
]
)
)
];
}
Please or to participate in this conversation.