Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aashish-t-magar committed Jan 11, 2024
1 parent d54579b commit 806393b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=intern_project
DB_USERNAME=postgres
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ public function index(){
}

//login module
/**
* Rename LoginFormValidator to LoginRequest
*
*/
public function login(LoginFormValidator $request){
try{
if(auth()->guard('admin')->attempt($request->only(['username', 'password']))):
return redirect()->intended('/admin/dashboard');
else:
return redirect()->back()->with('message', 'Invalid Credentials');
endif;

/**
*
* if there is already return function then no need to write else part.
*
*/
}catch(\Exception $e){
return redirect()->back()->with('message', $e->getMessage());
}
Expand All @@ -31,6 +41,13 @@ public function login(LoginFormValidator $request){
//logout module
public function logout(Request $request){
Auth::guard('admin')->logout();

/**
* remove Unnecesary codes
*
* $request->session()->invalidate();
* $request->session()->regenerateToken();
*/
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/admin-login');
Expand Down
16 changes: 16 additions & 0 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ public function index(Category $category)
*/
public function create(Category $category)
{

/**
* Alwyas try to paginate
*
* Write query in avariable instead of directly passing
*/
return view('backend.modals.admin-add-category', ['datas' => $category->whereNull('parent_id')
->orWhereHas('parent', fn ($query) => $query->whereNull('parent_id'))
->get()
]);
}

/**
* Rename CategoryFormValidator to CategoryFormRequest
*
*
* Store a newly created resource in storage.
*/
public function store(CategoryFormValidator $request)
Expand Down Expand Up @@ -60,6 +69,13 @@ public function show(Category $category)
public function edit(string $id)
{
try{

/**
* Always try to paginate instead of get();
* rename datas to data
*
*
*/
$editableData = Category::select('id', 'category_name','parent_id')->findOrFail($id);
$datas = Category::whereNull('parent_id')
->orWhereHas('parent', fn ($query) => $query->whereNull('parent_id'))
Expand Down

0 comments on commit 806393b

Please sign in to comment.