Hello,
I'm trying to upload an image with Orchid. This always fails with an error 500 / with the message "Validation error
File upload error ".
I kept to the specifications from the ORCHID documentation.
https://orchid.software/en/docs/quickstart-crud/
I did the following.
<?php
// Hero.php
namespace App\Models\LandingPage;
use Illuminate\Database\Eloquent\Model;
use Orchid\Attachment\Attachable;
use Orchid\Screen\AsSource;
class Hero extends Model {
use AsSource, Attachable;
/**
* @var array
*/
protected $fillable = [
'headline',
'tagline',
'content',
'href',
'href_text',
'image',
];
}
// HeroEditScreen
<?php
namespace App\Orchid\Screens\Pages\LandingPage;
use App\Models\LandingPage\Hero;
use Illuminate\Http\Request;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Picture;
use Orchid\Screen\Fields\Quill;
use Orchid\Screen\Fields\Relation;
use Orchid\Screen\Fields\TextArea;
use Orchid\Screen\Fields\Upload;
use Orchid\Screen\Layout;
use Orchid\Screen\Actions\Button;
use Orchid\Screen\Screen;
use Orchid\Support\Facades\Alert;
class HeroEditScreen extends Screen {
/**
* Display header name.
*
* @var string
*/
public $name = 'Create new hero item';
/**
* Display header description.
*
* @var string
*/
public $description = 'Set settings for the hero section on the landing page';
/**
* @var bool
*/
public $exists = false;
/**
* Query data.
*
* @param Hero $hero
* @return array
*/
public function query(Hero $hero): array {
$this->exists = $hero->exists;
if($this->exists){
$this->name = 'Edit post';
}
$hero->load('attachment');
return [
'hero' => $hero
];
}
/**
* Button commands.
*
* @return Link[]
*/
public function commandBar(): array {
return [
Button::make('Create item')
->icon('pencil')
->method('createOrUpdate')
->canSee(!$this->exists),
Button::make('Update')
->icon('note')
->method('createOrUpdate')
->canSee($this->exists),
Button::make('Remove')
->icon('trash')
->method('remove')
->canSee($this->exists),
];
}
/**
* Views.
*
* @return Layout[]
*/
public function layout(): array {
return [
Layout::columns([
Layout::rows([
Input::make('hero.headline')
->title('Headline')
->placeholder('Attractive but mysterious title')
->help('Specify a short descriptive title for this hero carousel item.'),
Input::make('hero.tagline')
->title('Tagline')
->placeholder('Attractive but mysterious title')
->help('Specify a short tagline.'),
TextArea::make('hero.content')
->title('Description')
->rows(3)
->maxlength(200)
->placeholder('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam.')
->help('Brief description for this item.'),
]),
Layout::rows([
Input::make('hero.href')
->title('Link')
->placeholder('www.google.com')
->help('Provide a link if required.'),
Input::make('hero.href_text')
->title('Link-Text')
->placeholder('Visit Googles')
->help('If a link exists, then return here to a text for the link.'),
]),
]),
Layout::columns([
Layout::rows([
Picture::make('hero.image')
->targetId()
])
])
];
}
/**
* @param Hero $hero
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function createOrUpdate(Hero $hero, Request $request) {
$hero->fill($request->get('hero'))->save();
$hero->attachment()->syncWithoutDetaching(
$request->input('hero.attachment', [])
);
Alert::info('You have successfully created an hero item.');
return redirect()->route('platform.hero.list');
}
/**
* @param Hero $hero
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function remove(Hero $hero) {
$hero->delete()
? Alert::info('You have successfully deleted the hero item.')
: Alert::warning('An error has occurred')
;
return redirect()->route('platform.hero.list');
}
}