mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
front-end article submission form added
This commit is contained in:
84
app/Http/Controllers/Api/LecturerController.php
Normal file
84
app/Http/Controllers/Api/LecturerController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Lecturer;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LecturerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
return Lecturer::query()
|
||||
->select('id', 'name',)
|
||||
->orderBy('name')
|
||||
->when(
|
||||
$request->search,
|
||||
fn(Builder $query) => $query
|
||||
->where('name', 'like', "%{$request->search}%")
|
||||
)
|
||||
->when(
|
||||
$request->exists('selected'),
|
||||
fn(Builder $query) => $query->whereIn('id', $request->input('selected', [])),
|
||||
fn(Builder $query) => $query->limit(10)
|
||||
)
|
||||
->get()
|
||||
->map(function (Lecturer $lecturer) {
|
||||
$lecturer->image = $lecturer->getFirstMediaUrl('avatar', 'thumb');
|
||||
|
||||
return $lecturer;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Lecturer $lecturer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Lecturer $lecturer)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Lecturer $lecturer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Lecturer $lecturer)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Lecturer $lecturer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Lecturer $lecturer)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,11 @@ class ArticleOverview extends Component
|
||||
])
|
||||
->where('type', 'markdown_article')
|
||||
->when(app()->environment('production'),
|
||||
fn($query) => $query->whereHas('createdBy.roles',
|
||||
fn($query) => $query->where('roles.name', 'news-editor')))
|
||||
fn($query) => $query
|
||||
->whereHas('createdBy.roles',
|
||||
fn($query) => $query->where('roles.name', 'news-editor'))
|
||||
)
|
||||
->where('approved', true)
|
||||
->orderByDesc('created_at')
|
||||
->get(),
|
||||
])->layout('layouts.app', [
|
||||
|
||||
79
app/Http/Livewire/News/Form/NewsArticleForm.php
Normal file
79
app/Http/Livewire/News/Form/NewsArticleForm.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\News\Form;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class NewsArticleForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public ?LibraryItem $libraryItem = null;
|
||||
public $image;
|
||||
public $currentImage = 0;
|
||||
public $images;
|
||||
public $imagesCloned = [];
|
||||
public array $temporaryUrls = [];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'image' => 'required|mimes:jpeg,png,jpg,gif|max:10240',
|
||||
|
||||
'libraryItem.lecturer_id' => 'required',
|
||||
'libraryItem.name' => 'required',
|
||||
'libraryItem.type' => 'required',
|
||||
'libraryItem.language_code' => 'required',
|
||||
'libraryItem.value' => 'required',
|
||||
'libraryItem.subtitle' => 'required',
|
||||
'libraryItem.excerpt' => 'required',
|
||||
'libraryItem.main_image_caption' => 'required',
|
||||
'libraryItem.read_time' => 'required',
|
||||
'libraryItem.approved' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if ($this->libraryItem === null) {
|
||||
$this->libraryItem = new LibraryItem([
|
||||
'type' => 'markdown_article',
|
||||
'value' => '',
|
||||
'read_time' => 1,
|
||||
'language_code' => 'de',
|
||||
'approved' => auth()
|
||||
->user()
|
||||
->hasRole('news-editor'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updatedImages($value)
|
||||
{
|
||||
$clonedImages = collect($this->imagesCloned);
|
||||
$clonedImages = $clonedImages->push($value);
|
||||
$this->imagesCloned = $clonedImages->toArray();
|
||||
|
||||
$temporaryUrls = collect($this->temporaryUrls);
|
||||
$temporaryUrls = $temporaryUrls->push($value->temporaryUrl());
|
||||
$this->temporaryUrls = $temporaryUrls->toArray();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
$this->libraryItem->save();
|
||||
|
||||
$this->libraryItem->addMedia($this->image)
|
||||
->toMediaCollection('main');
|
||||
|
||||
return to_route('article.overview', ['country' => null]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.news.form.news-article-form');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user