I used to work on Codeignitor for mobile app services but now I am instructed to use Laravel instead of Codeignitor.
In Codeignitor we can call a controller (API in my case) directly from a URL so with we can send some data, but in Laravel we can not call a controller directly from URL so we have to use routes to call a controller. So how would a mobile App would call and send data to a route then the route would call the corresponding service of the API?
I am new to Laravel so any help will a massive help.
These work the same as the would work on php or codeignitor .
POST method. in native php and codeignitor you get the input field by specifying POST method.However in Laravel You have to specify that in route . I hope you have some idea of MVC .You will specify your post route like that....
Route::post('/login', 'Api@Signin');
Here is a simple service which logs in the user.
public function Signin()
{
$validation = Validator::make(Request::all(),[
'email' => 'required',
'password' => 'required',
'device_type' => 'required',
'device_token' => 'required',
]);
if($validation->fails())
{
$finalResult = array('code' => 100,
'msg' => 'Data Entered Not Correct.',
'data' => array()
);
}
else
{
$login = User::where(
[
['email', '=', Input::get('email')],
['password', '=', md5(Input::get('password'))],
])->first();
if (is_null($login))
{
$finalResult = array('code' => 100,
'msg' => 'Your Account Does not exist.',
'data' => array()
);
}
else
{
$user= User::where('email', '=', Input::get('email'))->first();
$user->device_token = Input::get('device_token');
$user->device_type = Input::get('device_type');
$user->save();
$data = User::where(
[ 'email' =>Input::get('email')],
[ 'password' =>md5(Input::get('password'))]
)->get();
$finalResult = array('code' => 200,
'msg' => 'Success',
'data' => $data
);
}
}
echo json_encode($finalResult);
}