Initial Commit
This commit is contained in:
245
app/Livewire/Admin/Categories.php
Normal file
245
app/Livewire/Admin/Categories.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\ParentCategory;
|
||||
use App\Models\Category;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class Categories extends Component
|
||||
{
|
||||
|
||||
use WithPagination;
|
||||
|
||||
public $isUpdateParentCategoryMode = false;
|
||||
public $pcategory_id, $pcategory_name;
|
||||
|
||||
public $isUpdateCategoryMode = false;
|
||||
public $category_id, $parent = 0, $category_name;
|
||||
|
||||
public $pcategoriesPerPage = 8;
|
||||
public $categoriesPerPage = 10;
|
||||
|
||||
protected $listeners = [
|
||||
'updateCategoryOrdering',
|
||||
'updateParentCategoryOrdering',
|
||||
'deleteParentCategoryAction',
|
||||
'deleteCategoryAction'
|
||||
];
|
||||
|
||||
public function addParentCategory() {
|
||||
$this->pcategory_id = null;
|
||||
$this->pcategory_name = null;
|
||||
$this->isUpdateParentCategoryMode = false;
|
||||
$this->showParentCategoryModalForm();
|
||||
}
|
||||
|
||||
public function createParentCategory() {
|
||||
$this->validate([
|
||||
'pcategory_name' => 'required|unique:parent_categories,name'
|
||||
], [
|
||||
'pcategory_name.required' => 'Name wird benötigt',
|
||||
'pcategory_name.unique' => 'Name wird bereits verwendet',
|
||||
]);
|
||||
|
||||
$pcategory = new ParentCategory();
|
||||
$pcategory->name = $this->pcategory_name;
|
||||
$saved = $pcategory->save();
|
||||
|
||||
if($saved) {
|
||||
$this->hideParentCategoryModalForm();
|
||||
$this->dispatch("showToastr", ["type" => "success", "message" => "Neue Haupt Kategorie wurde erstellt"]);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ["type" => "error", "message" => "Haupt Kategorie konnte nicht erstellt werden"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function editParentCategory($id) {
|
||||
$pcategory = ParentCategory::findOrFail($id);
|
||||
$this->pcategory_id = $pcategory->id;
|
||||
$this->pcategory_name = $pcategory->name;
|
||||
$this->isUpdateParentCategoryMode = true;
|
||||
$this->showParentCategoryModalForm();
|
||||
}
|
||||
|
||||
public function updateParentCategory() {
|
||||
$pcategory = ParentCategory::findOrFail($this->pcategory_id);
|
||||
|
||||
$this->validate([
|
||||
'pcategory_name' => 'required|unique:parent_categories,name,'.$pcategory->id
|
||||
], [
|
||||
'pcategory_name.required' => 'Name wird benötigt',
|
||||
'pcategory_name.unique' => 'Name bereits vergeben',
|
||||
]);
|
||||
|
||||
$pcategory->name = $this->pcategory_name;
|
||||
$pcategory->slug = null;
|
||||
$updated = $pcategory->save();
|
||||
|
||||
if($updated) {
|
||||
$this->hideParentCategoryModalForm();
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Haupt Kategorie wurde erfolgreich bearbeitet']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Haupt Kategorie konnte nicht bearbeitet werden']);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateParentCategoryOrdering($positions) {
|
||||
foreach($positions as $position) {
|
||||
$index = $position[0];
|
||||
$new_position = $position[1];
|
||||
ParentCategory::where('id', $index)->update([
|
||||
'ordering' => $new_position
|
||||
]);
|
||||
}
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Haupt Kategorie wurde neu sortiert']);
|
||||
}
|
||||
|
||||
public function updateCategoryOrdering($positions) {
|
||||
foreach($positions as $position) {
|
||||
$index = $position[0];
|
||||
$new_position = $position[1];
|
||||
Category::where('id', $index)->update([
|
||||
'ordering' => $new_position
|
||||
]);
|
||||
}
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Kategorie wurde neu sortiert']);
|
||||
}
|
||||
|
||||
public function deleteParentCategory($id) {
|
||||
$this->dispatch('deleteParentCategory', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function deleteParentCategoryAction($id) {
|
||||
$pcategory = ParentCategory::findOrFail($id);
|
||||
|
||||
if($pcategory->children->count() > 0) {
|
||||
foreach($pcategory->children as $category) {
|
||||
Category::where('id', $category->id)->update(['parent' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
$delete = $pcategory->delete();
|
||||
|
||||
if($delete) {
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Haupt Kategorie wurde erfolgreich gelöscht']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim löschen der Haupt Kategorie']);
|
||||
}
|
||||
}
|
||||
|
||||
public function showParentCategoryModalForm() {
|
||||
$this->resetErrorBag();
|
||||
$this->dispatch("showParentCategoryModalForm");
|
||||
}
|
||||
|
||||
public function hideParentCategoryModalForm() {
|
||||
$this->dispatch("hideParentCategoryModalForm");
|
||||
$this->isUpdateParentCategoryMode = false;
|
||||
$this->pcategory_id = $this->pcategory_name = null;
|
||||
}
|
||||
|
||||
public function createCategory() {
|
||||
$this->validate([
|
||||
'category_name' => 'required|unique:categories,name'
|
||||
], [
|
||||
'category_name.required' => 'Kategorie Name wird benötigt',
|
||||
'category_name.unique' => 'Kategorie Name bereits vergeben'
|
||||
]);
|
||||
|
||||
$category = new Category();
|
||||
$category->parent = $this->parent;
|
||||
$category->name = $this->category_name;
|
||||
$saved = $category->save();
|
||||
|
||||
if($saved) {
|
||||
$this->hideCategoryModalForm();
|
||||
$this->dispatch("showToastr", ['type' => 'success', 'message' => 'Kategorie wurde erfolgreich erstellt']);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ['type' => 'error', 'message' => 'Kategorie konnte nicht erstellt werden']);
|
||||
}
|
||||
}
|
||||
|
||||
public function addCategory() {
|
||||
$this->pcategory_id = null;
|
||||
$this->parent = 0;
|
||||
$this->pcategory_name = null;
|
||||
$this->isUpdateCategoryMode = false;
|
||||
$this->showCategoryModalForm();
|
||||
}
|
||||
|
||||
public function showCategoryModalForm() {
|
||||
$this->resetErrorBag();
|
||||
$this->dispatch('showCategoryModalForm');
|
||||
}
|
||||
|
||||
public function hideCategoryModalForm() {
|
||||
$this->dispatch('hideCategoryModalForm');
|
||||
$this->isUpdateCategoryMdoe = false;
|
||||
$this->category_id = $this->category_name = null;
|
||||
$this->parent = 0;
|
||||
}
|
||||
|
||||
public function editCategory($id) {
|
||||
$category = Category::findOrFail($id);
|
||||
$this->category_id = $category->id;
|
||||
$this->parent = $category->parent;
|
||||
$this->category_name = $category->name;
|
||||
$this->isUpdateCategoryMode = true;
|
||||
$this->showCategoryModalForm();
|
||||
}
|
||||
|
||||
public function updateCategory() {
|
||||
$category = Category::findOrFail($this->category_id);
|
||||
$this->validate([
|
||||
'category_name' => 'required|unique:categories,name,'.$category->id
|
||||
], [
|
||||
'category_name.required' => 'Kategorie Name wird benötigt',
|
||||
'category_name.unique' => 'Kategorie Name bereits vergeben',
|
||||
]);
|
||||
|
||||
$category->name = $this->category_name;
|
||||
$category->parent = $this->parent;
|
||||
$category_slug = null;
|
||||
$updated = $category->save();
|
||||
|
||||
if($updated) {
|
||||
$this->hideCategoryModalForm();
|
||||
$this->dispatch("showToastr", ["type" => "success", "message" => "Kategorie wurde erfolgreich bearbeitet"]);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ["type" => "error", "message" => "Kategorie konnte nicht bearbeitet werden"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteCategory($id) {
|
||||
$this->dispatch('deleteCategory', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function deleteCategoryAction($id) {
|
||||
$category = Category::findOrFail($id);
|
||||
|
||||
iF($category->posts->count() > 0 ) {
|
||||
$count = $category->posts->count();
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => "Diese Kategorie hat ($count) Post/s. Kann daher nicht gelöscht werden"]);
|
||||
} else {
|
||||
$delete = $category->delete();
|
||||
|
||||
if($delete) {
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Kategorie wurde erfolgreich gelöscht']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim löschen der Kategorie']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.categories',
|
||||
[
|
||||
'pcategories' => ParentCategory::orderBy('ordering', 'asc')->paginate($this->pcategoriesPerPage, ["*"],'pcat_page'),
|
||||
'categories' => Category::orderBy('ordering', 'asc')->paginate($this->categoriesPerPage,["*"],'cat_page')
|
||||
]);
|
||||
}
|
||||
}
|
||||
146
app/Livewire/Admin/Posts.php
Normal file
146
app/Livewire/Admin/Posts.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Post;
|
||||
use Livewire\WithPagination;
|
||||
use App\Models\ParentCategory;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class Posts extends Component
|
||||
{
|
||||
|
||||
use WithPagination;
|
||||
|
||||
public $perPage = 10;
|
||||
public $categories_html;
|
||||
|
||||
public $search = null;
|
||||
public $author = null;
|
||||
public $category = null;
|
||||
public $visibility = null;
|
||||
public $sortBy = "desc";
|
||||
public $post_visibility;
|
||||
|
||||
protected $queryString = [
|
||||
'search' => ['except' => ''],
|
||||
'author' => ['except' => ''],
|
||||
'category' => ['except' => ''],
|
||||
'visibility' => ['except' => ''],
|
||||
'shortBy' => ['except' => ''],
|
||||
];
|
||||
|
||||
protected $listeners = [
|
||||
'deletePostAction'
|
||||
];
|
||||
|
||||
public function updatedSearch() {
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function updatedAuthor() {
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function updatedCategory() {
|
||||
$this->resetPage();
|
||||
}
|
||||
|
||||
public function updatedVisibility() {
|
||||
$this->resetPage();
|
||||
$this->post_visibility = $this->visibility == 'public' ? 1 : 0;
|
||||
}
|
||||
|
||||
public function mount() {
|
||||
$this->author = auth()->user()->type == "superAdmin" ? auth()->user()->id : '';
|
||||
$this->post_visibility = $this->visibility == 'public' ? 1 : 0;
|
||||
$categories_html = '';
|
||||
|
||||
$pcategories = ParentCategory::whereHas('children', function($q) {
|
||||
$q->whereHas('posts');
|
||||
})->orderBy('name', 'asc')->get();
|
||||
|
||||
$categories = Category::whereHas('posts')->where('parent', 0)->orderBy('name', 'asc')->get();
|
||||
|
||||
if(count($pcategories) > 0) {
|
||||
foreach($pcategories as $item) {
|
||||
$categories_html.='<optgroup label="'.$item->name.'">';
|
||||
foreach($item->children as $category) {
|
||||
if($category->posts->count() > 0) {
|
||||
$categories_html.='<option value="'.$category->id.'">'.$category->name.'</option>';
|
||||
}
|
||||
}
|
||||
$categories_html.='</optgroup>';
|
||||
}
|
||||
}
|
||||
|
||||
if(count($categories) > 0) {
|
||||
foreach($categories as $item) {
|
||||
$categories_html.='<option value="'.$item->id.'">'.$item->name.'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->categories_html = $categories_html;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.posts', [
|
||||
'posts' => auth()->user()->type == "superAdmin" ?
|
||||
Post::search(trim($this->search))
|
||||
->when($this->author, function($query) {
|
||||
$query->where('author_id', $this->author);
|
||||
})->when($this->category, function($query) {
|
||||
$query->where('category', $this->category);
|
||||
})->when($this->visibility, function($query) {
|
||||
$query->where('visibility', $this->post_visibility);
|
||||
})->when($this->sortBy, function($query) {
|
||||
$query->orderBy('id', $this->sortBy);
|
||||
})->paginate($this->perPage)
|
||||
: Post::search(trim($this->search))
|
||||
->when($this->author, function($query) {
|
||||
$query->where('author_id', $this->author);
|
||||
})->when($this->category, function($query) {
|
||||
$query->where('category', $this->category);
|
||||
})->when($this->visibility, function($query) {
|
||||
$query->where('visibility', $this->post_visibility);
|
||||
})->when($this->sortBy, function($query) {
|
||||
$query->orderBy('id', $this->sortBy);
|
||||
})->where('author_id', auth()->id())->paginate($this->perPage),
|
||||
]);
|
||||
}
|
||||
|
||||
public function deletePost($id) {
|
||||
$this->dispatch('deletePost', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function deletePostAction($id) {
|
||||
$post = Post::findOrFail($id);
|
||||
$path = "images/posts/";
|
||||
$resized_path = $path.'resized/';
|
||||
$old_featured_image = $post->featured_image;
|
||||
|
||||
if($old_featured_image != "" && File::exists(public_path($path.$old_featured_image))) {
|
||||
File::delete(public_path($path.$old_featured_image));
|
||||
|
||||
if(File::exists(public_path($resized_path.'resized_'.$old_featured_image))) {
|
||||
File::delete(public_path($resized_path.'resized_'.$old_featured_image));
|
||||
}
|
||||
|
||||
if(File::exists(public_path($resized_path.'thumb_'.$old_featured_image))) {
|
||||
File::delete(public_path($resized_path.'thumb_'.$old_featured_image));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$delete = $post->delete();
|
||||
|
||||
if($delete) {
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Post wurde erfolgreich gelöscht']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Post konnte nicht gelöscht werden']);
|
||||
}
|
||||
}
|
||||
}
|
||||
175
app/Livewire/Admin/Profile.php
Normal file
175
app/Livewire/Admin/Profile.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use App\Helpers\CMail;
|
||||
use App\Models\UserSocialLink;
|
||||
|
||||
class Profile extends Component
|
||||
{
|
||||
|
||||
public $tab = null;
|
||||
public $tabname = "personal_details";
|
||||
protected $queryString = ['tab' => ['keep' => true]];
|
||||
|
||||
public $name, $email, $username, $bio;
|
||||
public $current_password, $new_password, $new_password_confirmation;
|
||||
public $facebook_url, $instagram_url, $youtube_url, $linkedin_url, $twitter_url, $github_url;
|
||||
|
||||
protected $listeners = [
|
||||
'updateProfile' => '$refresh'
|
||||
];
|
||||
|
||||
public function selectTab($tab) {
|
||||
$this->tab = $tab;
|
||||
}
|
||||
|
||||
public function mount() {
|
||||
$this->tab = Request("tab") ? Request("tab") : $this->tabname;
|
||||
|
||||
$user = User::with("social_links")->findOrFail(auth()->id());
|
||||
$this->name = $user->name;
|
||||
$this->email = $user->email;
|
||||
$this->username = $user->username;
|
||||
$this->bio = $user->bio;
|
||||
|
||||
if(!is_null($user->social_links)) {
|
||||
$this->facebook_url = $user->social_links->facebook_url;
|
||||
$this->instagram_url = $user->social_links->instagram_url;
|
||||
$this->youtube_url = $user->social_links->youtube_url;
|
||||
$this->twitter_url = $user->social_links->twitter_url;
|
||||
$this->github_url = $user->social_links->github_url;
|
||||
$this->linkedin_url = $user->social_links->linkedin_url;
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePersonalDetails() {
|
||||
$user = User::findOrFail(auth()->id());
|
||||
|
||||
$this->validate([
|
||||
"name" => "required",
|
||||
"username" => "required|unique:users,username,".$user->id,
|
||||
], [
|
||||
"name.required" => "Name wird benötigt",
|
||||
"username.required" => "Benutzername wird benötigt",
|
||||
"username.unique" => "Benutzername bereits vergeben",
|
||||
]);
|
||||
|
||||
$user->name = $this->name;
|
||||
$user->username = $this->username;
|
||||
$user->bio = $this->bio;
|
||||
$updated = $user->save();
|
||||
|
||||
sleep(0.5);
|
||||
|
||||
if($updated) {
|
||||
$this->dispatch("showToastr", ["type" => "success", "message" => "Deine Profil Informationen wurden bearbeitet"]);
|
||||
$this->dispatch("updateTopUserInfo")->to(TopUserInfo::class);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ["type" => "error", "message" => "Deine Profil Informationen konnten nicht bearbeitet werden"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePassword(Request $request) {
|
||||
$user = User::findOrFail(auth()->id());
|
||||
|
||||
$this->validate([
|
||||
"current_password" => [
|
||||
"required",
|
||||
"min:5",
|
||||
function($attribute, $value, $fail) use ($user) {
|
||||
if(!Hash::check($value, $user->password)) {
|
||||
return $fail(__('Dein Passwort stimmt nicht überein'));
|
||||
}
|
||||
}
|
||||
],
|
||||
"new_password" => "required|min:5|confirmed"
|
||||
], [
|
||||
"current_password.required" => "Das aktuelle Passwort wird benötigt",
|
||||
"current_password.min" => "Gebe mind. 5 Zeichen ein",
|
||||
"new_password.required" => "Das aktuelle Passwort wird benötigt",
|
||||
"new_password.min" => "Gebe mind. 5 Zeichen ein",
|
||||
]);
|
||||
|
||||
$updated = $user->update([
|
||||
"password" => Hash::make($this->new_password)
|
||||
]);
|
||||
|
||||
if($updated) {
|
||||
$data = array(
|
||||
"user" => $user,
|
||||
"new_password" => $this->new_password
|
||||
);
|
||||
|
||||
$mail_body = view("email-templates.password-changes-template", $data)->render();
|
||||
|
||||
$mail_config = array(
|
||||
'recipient_address' => $user->email,
|
||||
'recipient_name' => $user->name,
|
||||
"subject" => "Passwort geändert",
|
||||
"body" => $mail_body
|
||||
);
|
||||
|
||||
CMail::send($mail_config);
|
||||
auth()->logout();
|
||||
Session::flash("info", "Dein Passwort wurde geändert, bitte logge dich neu ein");
|
||||
$this->redirectRoute("admin.login");
|
||||
} else {
|
||||
$this->dispatch("showToastr", ["type" => "error", "message" => "Leider lief etwas schief"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSocialLinks() {
|
||||
$this->validate([
|
||||
'facebook_url' => 'nullable|url',
|
||||
'instagram_url' => 'nullable|url',
|
||||
'youtube_url' => 'nullable|url',
|
||||
'linkedin_url' => 'nullable|url',
|
||||
'twitter_url' => 'nullable|url',
|
||||
'github_url' => 'nullable|url',
|
||||
],[
|
||||
'facebook_url.url' => "Du musst einen gültigen Link angeben",
|
||||
'instagram_url.url' => "Du musst einen gültigen Link angeben",
|
||||
'youtube_url.url' => "Du musst einen gültigen Link angeben",
|
||||
'linkedin_url.url' => "Du musst einen gültigen Link angeben",
|
||||
'twitter_url.url' => "Du musst einen gültigen Link angeben",
|
||||
'github_url.url' => "Du musst einen gültigen Link angeben",
|
||||
]);
|
||||
|
||||
$user = User::findOrFail(auth()->id());
|
||||
|
||||
$data = array(
|
||||
'instagram_url' => $this->instagram_url,
|
||||
'facebook_url' => $this->facebook_url,
|
||||
'youtube_url' => $this->youtube_url,
|
||||
'linkedin_url' => $this->linkedin_url,
|
||||
'twitter_url' => $this->twitter_url,
|
||||
'github_url' => $this->github_url,
|
||||
);
|
||||
|
||||
if(!is_null($user->social_links)) {
|
||||
$query = $user->social_links()->update($data);
|
||||
} else {
|
||||
$data['user_id'] = $user->id;
|
||||
$query = UserSocialLink::insert($data);
|
||||
}
|
||||
|
||||
if($query) {
|
||||
$this->dispatch("showToastr", ["type" => "success", "message"=> "Social Links erfolgreich bearbeitet"]);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ["type" => "error", "message"=> "Fehler beim bearbeiten von Social Links"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.profile', [
|
||||
"user" => User::findOrFail(auth()->id())
|
||||
]);
|
||||
}
|
||||
}
|
||||
122
app/Livewire/Admin/Settings.php
Normal file
122
app/Livewire/Admin/Settings.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\GeneralSetting;
|
||||
use App\Models\SiteSocialLink;
|
||||
|
||||
class Settings extends Component
|
||||
{
|
||||
public $tab = null;
|
||||
public $default_tab = 'general_settings';
|
||||
protected $queryString = ['tab' => ['keep' => true]];
|
||||
|
||||
// Allgemein Settings form Properties
|
||||
public $site_title, $site_email, $site_phone, $site_meta_keywords, $site_meta_description;
|
||||
|
||||
// Seiten Social Links
|
||||
public $facebook_url, $instagram_url, $linkedin_url, $twitter_url;
|
||||
|
||||
public function selectTab($tab) {
|
||||
$this->tab = $tab;
|
||||
}
|
||||
|
||||
public function mount() {
|
||||
$this->tab = Request('tab') ? Request('tab') : $this->default_tab;
|
||||
|
||||
$settings = GeneralSetting::take(1)->first();
|
||||
|
||||
// Site Social Links
|
||||
$site_social_links = SiteSocialLink::take(1)->first();
|
||||
|
||||
if(!is_null($settings)) {
|
||||
$this->site_title = $settings->site_title;
|
||||
$this->site_email = $settings->site_email;
|
||||
$this->site_phone = $settings->site_phone;
|
||||
$this->site_meta_keywords = $settings->site_meta_keywords;
|
||||
$this->site_meta_description = $settings->site_meta_description;
|
||||
}
|
||||
|
||||
if(!is_null($site_social_links)) {
|
||||
$this->facebook_url = $site_social_links->facebook_url;
|
||||
$this->instagram_url = $site_social_links->instagram_url;
|
||||
$this->linkedin_url = $site_social_links->linkedin_url;
|
||||
$this->twitter_url = $site_social_links->twitter_url;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSiteInfo() {
|
||||
$this->validate([
|
||||
'site_title' => 'required',
|
||||
'site_email' => 'required|email'
|
||||
], [
|
||||
'site_title.required' => "Seiten Titel wird benötigt",
|
||||
'site_email.required' => "Seiten Titel wird benötigt",
|
||||
'site_email.email' => "Gebe eine gültige Email an",
|
||||
]);
|
||||
|
||||
// Allgemeine Einstellungen
|
||||
$settings = GeneralSetting::take(1)->first();
|
||||
|
||||
$data = array(
|
||||
'site_title' => $this->site_title,
|
||||
'site_email' => $this->site_email,
|
||||
'site_phone' => $this->site_phone,
|
||||
'site_meta_keywords' => $this->site_meta_keywords,
|
||||
'site_meta_description' => $this->site_meta_description,
|
||||
);
|
||||
|
||||
if(!is_null($settings)) {
|
||||
$query = $settings->update($data);
|
||||
} else {
|
||||
$query = GeneralSetting::insert($data);
|
||||
}
|
||||
|
||||
if($query) {
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Einstellungen wurden gespeichert']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim speichern']);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSiteSocialLinks() {
|
||||
$this->validate([
|
||||
'facebook_url' => 'nullable|url',
|
||||
'instagram_url' => 'nullable|url',
|
||||
'linkedin_url' => 'nullable|url',
|
||||
'twitter_url' => 'nullable|url',
|
||||
], [
|
||||
'facebook_url.url' => 'Bitte gebe eine gültige URL ein',
|
||||
'instagram_url.url' => 'Bitte gebe eine gültige URL ein',
|
||||
'linkedin_url.url' => 'Bitte gebe eine gültige URL ein',
|
||||
'twitter_url.url' => 'Bitte gebe eine gültige URL ein',
|
||||
]);
|
||||
|
||||
$site_social_links = SiteSocialLink::take(1)->first();
|
||||
|
||||
$data = array(
|
||||
'facebook_url' => $this->facebook_url,
|
||||
'instagram_url' => $this->instagram_url,
|
||||
'linkedin_url' => $this->linkedin_url,
|
||||
'twitter_url' => $this->twitter_url,
|
||||
);
|
||||
|
||||
if(!is_null($site_social_links)) {
|
||||
$query = $site_social_links->update($data);
|
||||
} else {
|
||||
$query = SiteSocialLink::create($data);
|
||||
}
|
||||
|
||||
if($query) {
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Social Links wurden gespeichert']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim speichern']);
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.settings');
|
||||
}
|
||||
}
|
||||
190
app/Livewire/Admin/Slides.php
Normal file
190
app/Livewire/Admin/Slides.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use App\Models\Slide;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class Slides extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
|
||||
public $isUpdateSlideMode = false;
|
||||
public $slide_id, $slide_heading, $slide_link, $slide_image, $slide_status = true;
|
||||
public $selected_slide_image = null;
|
||||
|
||||
protected $listeners = [
|
||||
'updateSlidesOrdering',
|
||||
'deleteSlideAction'
|
||||
];
|
||||
|
||||
public function updatedSlideImage() {
|
||||
if($this->slide_image) {
|
||||
$this->selected_slide_image = $this->slide_image->temporaryUrl();
|
||||
}
|
||||
}
|
||||
|
||||
public function addSlide() {
|
||||
$this->slide_id = null;
|
||||
$this->slide_heading = null;
|
||||
$this->slide_link = null;
|
||||
$this->selected_slide_image = null;
|
||||
$this->slide_status = true;
|
||||
$this->isUpdateSlideMode = false;
|
||||
$this->showSlidemodalForm();
|
||||
}
|
||||
|
||||
public function showSlideModalForm() {
|
||||
$this->resetErrorBag();
|
||||
$this->dispatch('showSlideModalForm');
|
||||
}
|
||||
|
||||
public function hideSlideModalForm() {
|
||||
$this->dispatch('hideSlideModalForm');
|
||||
$this->isUpdateSlideMode = false;
|
||||
$this->slide_id = $this->slide_heading = $this->slide_link = $this->slide_image = null;
|
||||
$this->slide_status = true;
|
||||
}
|
||||
|
||||
public function createSlide() {
|
||||
$this->validate([
|
||||
'slide_heading' => 'required',
|
||||
'slide_link' => 'nullable|url',
|
||||
'slide_image' => 'required'
|
||||
], [
|
||||
'slide_heading.required' => 'Der Text wird benötigt',
|
||||
'slide_link.url' => 'Gebe einen gültigen Link ein',
|
||||
'slide_image.required' => 'Bild wird benötigt',
|
||||
]);
|
||||
|
||||
$path = "slides/";
|
||||
$file = $this->slide_image;
|
||||
$filename = "SLD_".date("YmdHis", time()).'.'.$file->getClientOriginalExtension();
|
||||
|
||||
$upload = $file->storeAs($path, $filename, 'slides_uploads');
|
||||
|
||||
if(!$upload) {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim Hochladen von Image']);
|
||||
} else {
|
||||
$slide = new Slide();
|
||||
$slide->image = $filename;
|
||||
$slide->heading = $this->slide_heading;
|
||||
$slide->link = $this->slide_link;
|
||||
$slide->status = $this->slide_status == true ? 1 : 0;
|
||||
$saved = $slide->save();
|
||||
|
||||
if($saved) {
|
||||
$this->hideSlideModalForm();
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Slider wurde erstellt']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim erstellen von Slider']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function editSlide($id) {
|
||||
$slide = Slide::findOrFail($id);
|
||||
$this->slide_id = $slide->id;
|
||||
$this->slide_heading = $slide->heading;
|
||||
$this->slide_link = $slide->link;
|
||||
$this->slide_status = $slide->status == 1 ? true : false;
|
||||
$this->slide_image = null;
|
||||
$this->selected_slide_image = "/images/slides/".$slide->image;
|
||||
$this->isUpdateSlideMode = true;
|
||||
$this->showSlidemodalForm();
|
||||
}
|
||||
|
||||
|
||||
public function updateSlide() {
|
||||
$slide = Slide::findOrFail($this->slide_id);
|
||||
|
||||
$this->validate([
|
||||
'slide_heading' => 'required',
|
||||
'slide_link' => 'nullable|url',
|
||||
'slide_image' => 'nullable'
|
||||
], [
|
||||
'slide_heading.required' => 'Der Text wird benötigt',
|
||||
'slide_link.url' => 'Gebe einen gültigen Link ein',
|
||||
]);
|
||||
|
||||
$slide_image_name = $slide->image;
|
||||
|
||||
if($this->slide_image) {
|
||||
$path = 'slides/';
|
||||
$file = $this->slide_image;
|
||||
$filename = 'SLD_'.date('YmdHis', time()).'.'.
|
||||
$file->getClientOriginalExtension();
|
||||
|
||||
$upload = $file->storeAs($path, $filename, 'slides_uploads');
|
||||
|
||||
if(!$upload) {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim Hochladen von Image']);
|
||||
} else {
|
||||
$slide_path = 'images/'.$path;
|
||||
$old_slide_image = $slide->image;
|
||||
|
||||
if($old_slide_image != '' && File::exists(public_path($slide_path.$old_slide_image))) {
|
||||
File::delete(public_path($slide_path.$old_slide_image));
|
||||
}
|
||||
|
||||
$slide_image_name = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$slide->image = $slide_image_name;
|
||||
$slide->heading = $this->slide_heading;
|
||||
$slide->link = $this->slide_link;
|
||||
$slide->status = $this->slide_status == true ? 1 : 0;
|
||||
$saved = $slide->save();
|
||||
|
||||
if($saved) {
|
||||
$this->hideSlideModalForm();
|
||||
$this->dispatch('showToastr', ['type' => 'success', 'message' => 'Slider wurde bearbeitet']);
|
||||
} else {
|
||||
$this->dispatch('showToastr', ['type' => 'error', 'message' => 'Fehler beim bearbeiten von Slider']);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSlidesOrdering($positions) {
|
||||
foreach($positions as $position) {
|
||||
$index = $position[0];
|
||||
$newPosition = $position[1];
|
||||
Slide::where('id', $index)->update([
|
||||
'ordering' => $newPosition
|
||||
]);
|
||||
$this->dispatch("showToastr", ['type' => "success", "message" => "Slides wurden neu angeordnet"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteSlideAction($id) {
|
||||
$slide = Slide::findOrFail($id);
|
||||
$path = "slides/";
|
||||
$slide_path = "images/".$path;
|
||||
$slide_image = $slide->image;
|
||||
|
||||
if($slide_image != '' && File::exists(public_path($slide_path.$slide_image))) {
|
||||
File::delete(public_path($slide_path.$slide_image));
|
||||
}
|
||||
|
||||
$delete = $slide->delete();
|
||||
|
||||
if($delete) {
|
||||
$this->dispatch("showToastr", ['type' => "success", "message" => "Slide wurden gelöscht"]);
|
||||
} else {
|
||||
$this->dispatch("showToastr", ['type' => "error", "message" => "Slide konnte nicht gelöscht werden"]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.slides', [
|
||||
'slides' => Slide::orderBy('ordering', 'asc')->get()
|
||||
]);
|
||||
}
|
||||
}
|
||||
21
app/Livewire/Admin/TopUserInfo.php
Normal file
21
app/Livewire/Admin/TopUserInfo.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\User;
|
||||
|
||||
class TopUserInfo extends Component
|
||||
{
|
||||
|
||||
protected $listeners = [
|
||||
"updateTopUserInfo" => '$refresh'
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.admin.top-user-info', [
|
||||
"user" => User::findOrFail(auth()->id())
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user