-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c28bb9
commit 17c3426
Showing
72 changed files
with
10,173 additions
and
2,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Blog; | ||
|
||
use App\Models\Blog; | ||
use Livewire\Component; | ||
use Livewire\WithFileUploads; | ||
use Illuminate\Support\Str; | ||
class Create extends Component | ||
{ | ||
use WithFileUploads; | ||
|
||
public $title; | ||
|
||
public $body = "# hello peoples"; | ||
|
||
public $message; | ||
|
||
public $photo; | ||
|
||
protected $rules = [ | ||
// 'cover_image' => ['required', 'mimes:png,jpg,svg,gif', 'max:2048'], | ||
'title' => ['required', 'max:200', 'min:20'], | ||
'body' => ['required', 'min:20'], | ||
|
||
]; | ||
|
||
public function render() | ||
{ | ||
return view('livewire.blog.create'); | ||
} | ||
|
||
public function updatedPhoto() | ||
|
||
{ | ||
$this->validate([ | ||
|
||
'photo' => 'image|max:1024', // 1MB Max | ||
|
||
]); | ||
} | ||
public function submit() | ||
|
||
{ | ||
$this->validate(); | ||
$blog = Blog::create([ | ||
'title'=>$this->title, | ||
'body'=>$this->body, | ||
'user_id'=>auth()->id() | ||
]); | ||
return redirect()->to('/blogs/'.Str::slug($this->title, '-').'-'.$blog->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Blog; | ||
|
||
use App\Models\Blog; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class Index extends Component | ||
{ | ||
use WithPagination; | ||
public $tab = 'recent'; | ||
|
||
protected $queryString = [ | ||
'tab' => ['except' => 'recent'] | ||
]; | ||
|
||
public function render() | ||
{ | ||
if ($this->validSort($this->tab)) { | ||
$blogs = Blog::published()->{$this->tab}()->paginate(10); | ||
} else { | ||
$this->tab = 'recent'; | ||
$blogs = Blog::published()->{$this->tab}()->paginate(10); | ||
} | ||
|
||
return view('livewire.blog.index')->with(["blogs" => $blogs, "tab" => $this->tab]); | ||
} | ||
public function sortBy($sort): void | ||
{ | ||
$this->tab = $this->validSort($sort) ? $sort : 'recent'; | ||
} | ||
public function validSort($sort): bool | ||
{ | ||
return in_array($sort, [ | ||
'recent', | ||
'popular', | ||
'view' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Blog; | ||
|
||
use Livewire\Component; | ||
|
||
class Show extends Component | ||
{ | ||
public function render() | ||
{ | ||
return view('livewire.blog.show'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Blog; | ||
|
||
use App\Models\Blog; | ||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; | ||
use Livewire\Component; | ||
use Livewire\WithFileUploads; | ||
use Illuminate\Support\Str; | ||
class Update extends Component | ||
{ | ||
use WithFileUploads; | ||
use AuthorizesRequests; | ||
public $title; | ||
|
||
public $body ; | ||
public $blog; | ||
|
||
public $message; | ||
|
||
public $photo; | ||
|
||
protected $rules = [ | ||
// 'cover_image' => ['required', 'mimes:png,jpg,svg,gif', 'max:2048'], | ||
'title' => ['required', 'max:200', 'min:20'], | ||
'body' => ['required', 'min:20'], | ||
|
||
]; | ||
public function mount(Blog $blog){ | ||
$this->blog=$blog; | ||
$this->title=$blog->title(); | ||
$this->body=$blog->body(); | ||
} | ||
public function render() | ||
{ | ||
$this->authorize('view', $this->blog); | ||
return view('livewire.blog.update'); | ||
} | ||
public function update() | ||
|
||
{ | ||
$this->authorize('update', $this->blog); | ||
$this->validate(); | ||
$blog = Blog::create([ | ||
'title'=>$this->title, | ||
'body'=>$this->body, | ||
'user_id'=>auth()->id() | ||
]); | ||
return redirect()->to('/blogs/'.Str::slug($this->title, '-').'-'.$blog->id); | ||
} | ||
} |
Oops, something went wrong.