Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting to get rid of Controller class #92

Merged
merged 16 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Homestead.yaml
!themes/.gitignore
/resources/assets/ckeditor45
/resources/assets/ckeditor/samples
/database/*.db
/database/*.db
.phpunit.result.cache
TESTS-*.xml
18 changes: 6 additions & 12 deletions app/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace App\Controllers\Auth;

use App\Libs\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use \App\Libs\ViewResolver;

class ForgotPasswordController extends Controller
{
Expand All @@ -26,21 +25,16 @@ class ForgotPasswordController extends Controller
*
* @return void
*/
public function __construct(ViewResolver $viewResolver)
public function __construct()
{

$this->view = $viewResolver;
$this->middleware('guest');

}

public function showLinkRequestForm()
{
$this->view->title("Forgot password");
return $this->view->render('auth/passwords/email',[
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
return view('auth.passwords.email', [
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
}

}
38 changes: 18 additions & 20 deletions app/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace App\Controllers\Auth;


use App\Libs\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use \App\Libs\ViewResolver;

class LoginController extends Controller
{
Expand All @@ -28,9 +26,8 @@ class LoginController extends Controller
*
* @return void
*/
public function __construct(Request $request, ViewResolver $viewResolver){
parent::__construct($request,$viewResolver);

public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}

Expand All @@ -39,16 +36,18 @@ public function __construct(Request $request, ViewResolver $viewResolver){
*
* @var string
*/
public function redirectTo(){
public function redirectTo()
{
return route('dashboard.index');
}

/**
*
* Returns if email or username is for authentication.
*/
*
* Returns if email or username is for authentication.
*/

public function username(){
public function username()
{
return 'username';
}

Expand All @@ -58,25 +57,24 @@ public function username(){
*
* @return \Illuminate\Http\Response
*/
public function showLoginForm(){
public function showLoginForm()
{

$this->view->title('Welcome');
return $this->view->render('auth/login',[
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
return view('auth.login', [
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
}



public function logout(Request $request){
public function logout(Request $request)
{

$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate(true);

return redirect(route('login'));
}


}
12 changes: 3 additions & 9 deletions app/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Controllers\Auth;

use App\Libs\Controller;
use Illuminate\Routing\Controller;
use App\Model\User;
use Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use \App\Libs\ViewResolver;

class RegisterController extends Controller
{
Expand Down Expand Up @@ -35,19 +34,14 @@ class RegisterController extends Controller
*
* @return void
*/
public function __construct(ViewResolver $viewResolver)
public function __construct()
{

$this->view = $viewResolver;

$this->middleware('guest');

$this->view->title("Register");
}

public function showRegistrationForm()
{
return $this->view->render('auth/register');
return view('auth.register');
}


Expand Down
20 changes: 8 additions & 12 deletions app/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace App\Controllers\Auth;


use App\Libs\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use \App\Libs\ViewResolver;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class ResetPasswordController extends Controller
{
Expand All @@ -31,21 +29,20 @@ class ResetPasswordController extends Controller
*
* @return void
*/
public function __construct(Request $request,ViewResolver $viewResolver)
public function __construct()
{
$this->view = $viewResolver;
$this->middleware('guest');

}


public function showResetForm(Request $request, $token = null)
{
$this->view->title("Password reset");
return $this->view->render('auth/passwords/reset',['token' => $token, 'email' => $request->email,
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
return view('auth.passwords.reset', [
'token' => $token,
'email' => $request->email,
'app_name' => \Config::get('app.name'),
'admin_logo' => url(\Config::get('horizontcms.admin_logo')),
]);
}


Expand All @@ -69,5 +66,4 @@ protected function resetPassword($user, $password)

$this->guard()->login($user);
}

}
30 changes: 11 additions & 19 deletions app/Controllers/BlogpostCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Controllers\Trait\UploadsImage;
use Illuminate\Http\Request;
use App\Libs\Controller;
use Illuminate\Routing\Controller;

use App\Model\BlogpostCategory;

Expand All @@ -22,11 +22,7 @@ class BlogpostCategoryController extends Controller
*/
public function index()
{



$this->view->title(trans('category.category'));
return $this->view->render('blogposts/category/index', [
return view('blogposts.category.index', [
'all_category' => BlogpostCategory::all(),
]);
}
Expand All @@ -36,9 +32,7 @@ public function index()
*
* @return \Illuminate\Http\Response
*/
public function create()
{
}
public function create() {}

/**
* Store a newly created resource in storage.
Expand All @@ -56,9 +50,9 @@ public function store(Request $request)
$this->uploadImage($blogpost_category);

if ($blogpost_category->save()) {
return $this->redirectToSelf()->withMessage(['success' => trans('message.successfully_created_blogpost_category')]);
return redirect()->back()->withMessage(['success' => trans('message.successfully_created_blogpost_category')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -70,8 +64,7 @@ public function store(Request $request)
*/
public function show(BlogpostCategory $blogpostcategory)
{
$this->view->title(trans('category.category'));
return $this->view->render('blogposts.category.view', ['category' => $blogpostcategory]);
return view('blogposts.category.view', ['category' => $blogpostcategory]);
}

/**
Expand All @@ -82,9 +75,8 @@ public function show(BlogpostCategory $blogpostcategory)
*/
public function edit(BlogpostCategory $blogpostcategory)
{
$this->view->title(trans('blogpost.edit_blogpost'));

return $this->view->render('blogposts/category/edit', [
return view('blogposts.category.edit', [
'category' => $blogpostcategory,
]);
}
Expand All @@ -104,9 +96,9 @@ public function update(Request $request, BlogpostCategory $blogpostcategory)
$this->uploadImage($blogpostcategory);

if ($blogpostcategory->save()) {
return $this->redirectToSelf()->withMessage(['success' => trans('message.successfully_updated_blogpost_category')]);
return redirect()->back()->withMessage(['success' => trans('message.successfully_updated_blogpost_category')]);
} else {
return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}

Expand All @@ -120,9 +112,9 @@ public function destroy(BlogpostCategory $blogpostcategory)
{

if ($blogpostcategory->delete()) {
return $this->redirectToSelf()->withMessage(['success' => trans('message.successfully_deleted_blogpost_category')]);
return redirect()->back()->withMessage(['success' => trans('message.successfully_deleted_blogpost_category')]);
}

return $this->redirectToSelf()->withMessage(['danger' => trans('message.something_went_wrong')]);
return redirect()->back()->withMessage(['danger' => trans('message.something_went_wrong')]);
}
}
8 changes: 4 additions & 4 deletions app/Controllers/BlogpostCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Controllers;

use Illuminate\Http\Request;
use App\Libs\Controller;
use Illuminate\Routing\Controller;

use App\Model\BlogpostComment;

Expand Down Expand Up @@ -33,7 +33,7 @@ public function store(Request $request)
$blogpost_comment->blogpost_id = $request->input('blogpost_id');
$blogpost_comment->author()->associate($request->user());

return $this->redirectToSelf()->withMessage(
return redirect()->back()->withMessage(
$blogpost_comment->save() ? ['success' => trans('message.successfully_created_blogpost_comment')]
: ['danger' => trans('message.something_went_wrong')]
);
Expand Down Expand Up @@ -64,7 +64,7 @@ public function update(BlogpostComment $blogpost_comment)
$blogpost_comment->author()->associate($this->request->user());


return $this->redirectToSelf()->withMessage(
return redirect()->back()->withMessage(
$blogpost_comment->save() ? ['success' => trans('message.successfully_updated_blogpost_comment')]
: ['danger' => trans('message.something_went_wrong')]
);
Expand All @@ -80,7 +80,7 @@ public function destroy(BlogpostComment $blogpostcomment)
{


return $this->redirectToSelf()->withMessage(
return redirect()->back()->withMessage(
$blogpostcomment->delete() ? ['success' => trans('message.successfully_deleted_blogpost_comment')]
: ['danger' => trans('message.something_went_wrong')]
);
Expand Down
Loading
Loading