-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from xs-shahin/laravel-mongo
Laravel mongo
- Loading branch information
Showing
62 changed files
with
1,233 additions
and
63 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
<?php | ||
|
||
namespace Xpeedstudio\Hr\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Validator; | ||
use Xpeedstudio\Hr\Helpers\Helper; | ||
use Xpeedstudio\Hr\Models\Country; | ||
use Xpeedstudio\Hr\Models\Region; | ||
|
||
class CountryController extends Controller | ||
{ | ||
public function index(Request $request) | ||
{ | ||
$perPage = $request->input('per_page', 10); // Number of results per page (default: 10) | ||
$search = $request->input('search', ''); // Search query (default: empty string) | ||
|
||
$countries = Country::with('region') | ||
->when($search, function ($query, $search) { | ||
return $query->where('country_name', 'like', '%' . $search . '%'); | ||
}) | ||
->paginate($perPage); | ||
|
||
return response()->json([ | ||
'countries' => $countries, | ||
]); | ||
|
||
return view('xpeedstudio/hr::country.index', compact('countries')); | ||
} | ||
public function create() | ||
{ | ||
$regions = Region::all(); | ||
|
||
return view('xpeedstudio/hr::country.create', compact('regions')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validator = Validator::make($request->all(), [ | ||
'country_name' => 'required', | ||
'region_id' => 'required|exists:regions,id' | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return response()->json([ | ||
'errors' => $validator->errors() | ||
], 422); // HTTP status code for Unprocessable Entity | ||
} | ||
|
||
// If validation passes, create the employee | ||
$data = Country::create($request->all()); | ||
|
||
return response()->json([ | ||
'message' => 'Country created successfully.', | ||
'data' => [$data] | ||
], 201); // HTTP status code for Created | ||
} | ||
|
||
public function show($id) | ||
{ | ||
$countries = Country::find($id); | ||
return response()->json([ | ||
'message' => 'Country created successfully.', | ||
'data' => [ | ||
'countries' => $countries | ||
] | ||
], 201); // HTTP status code for Created | ||
|
||
return view('xpeedstudio/hr::country.show', compact('countries')); | ||
} | ||
} |
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
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,64 @@ | ||
<?php | ||
|
||
namespace Xpeedstudio\Hr\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Xpeedstudio\Hr\Models\Job; | ||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Validator; | ||
|
||
class JobController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$jobs = Job::all(); | ||
|
||
return response()->json([ | ||
'jobs' => $jobs, | ||
]); | ||
|
||
return view('xpeedstudio/hr::job.index', compact('jobs')); | ||
} | ||
public function create() | ||
{ | ||
$jobs = Job::all(); | ||
|
||
return view('xpeedstudio/hr::job.create', compact('jobs')); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$validator = Validator::make($request->all(), [ | ||
'job_title' => 'required', | ||
'min_salary' => 'required', | ||
'max_salary' => 'nullable', | ||
]); | ||
|
||
if ($validator->fails()) { | ||
return response()->json([ | ||
'errors' => $validator->errors() | ||
], 422); // HTTP status code for Unprocessable Entity | ||
} | ||
|
||
// If validation passes, create the employee | ||
$data = Job::create($request->all()); | ||
|
||
return response()->json([ | ||
'message' => 'Job created successfully.', | ||
'data' => [$data] | ||
], 201); // HTTP status code for Created | ||
} | ||
|
||
public function show($id) | ||
{ | ||
$job = Job::find($id); | ||
return response()->json([ | ||
'message' => 'Job created successfully.', | ||
'data' => [ | ||
'job' => $job | ||
] | ||
], 201); // HTTP status code for Created | ||
|
||
return view('xpeedstudio/hr::job.show', compact('job')); | ||
} | ||
} |
Oops, something went wrong.