本文整理汇总了PHP中Illuminate\Http\Request::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::has方法的具体用法?PHP Request::has怎么用?PHP Request::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticated
/**
* Overrides the action when a user is authenticated.
* If the user authenticated but does not exist in the user table we create them.
* @param Request $request
* @param Authenticatable $user
* @return \Illuminate\Http\RedirectResponse
* @throws AuthException
*/
protected function authenticated(Request $request, Authenticatable $user)
{
// Explicitly log them out for now if they do no exist.
if (!$user->exists) {
auth()->logout($user);
}
if (!$user->exists && $user->email === null && !$request->has('email')) {
$request->flash();
session()->flash('request-email', true);
return redirect('/login');
}
if (!$user->exists && $user->email === null && $request->has('email')) {
$user->email = $request->get('email');
}
if (!$user->exists) {
// Check for users with same email already
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
if ($alreadyUser) {
throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
}
$user->save();
$this->userRepo->attachDefaultRole($user);
auth()->login($user);
}
$path = session()->pull('url.intended', '/');
$path = baseUrl($path, true);
return redirect($path);
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = Items::find($id);
if ($data) {
if ($request->has('name')) {
$data->name = $request->input('name');
}
if ($request->has('status') && ($status = States::find($request->input('status')))) {
$data->status = $status->id;
}
if ($request->has('user_id') && ($person = Persons::find($request->input('user_id')))) {
$data->user_id = $person->id;
}
if ($request->has('title')) {
$data->title = $request->input('title');
}
if ($request->has('description')) {
$data->description = $request->input('description');
}
if ($data->save()) {
return $this->success($data);
} else {
return $this->error("failed to save");
}
} else {
return $this->error("No person with this id");
}
}
示例3: index
public function index(Request $request)
{
$scope = [];
if ($request->has('title')) {
$scope['title'] = ['LIKE', '%' . $request->input('title') . '%'];
}
if ($request->has('host')) {
$scope['host'] = ['LIKE', '%' . $request->input('host') . '%'];
}
if ($request->has('introduction')) {
$scope['introduction'] = ['LIKE', '%' . $request->input('introduction') . '%'];
}
$params = $request->except('page');
if ($request->has('sort')) {
$params['sort'] = $request->input('sort');
} else {
$params['sort'] = 'id';
}
if ($request->has('order')) {
$params['order'] = $request->input('order');
} else {
$params['order'] = 'desc';
}
$fts = Ft::select('id', 'title', 'host', 'poster_url', 'introduction')->multiwhere($scope)->orderBy($params['sort'], $params['order'])->paginate(30);
return view('ft.index', ['params' => $params, 'fts' => $fts]);
}
示例4: getEvents
/**
* @param Illuminate\Http\Request $request
* @param string $device
* @return json events
*/
public function getEvents(Request $request, $device)
{
/**
* Limit events
* @var integer
*/
$limit = 10;
/**
* Start at timestamp
* @var integer
*/
$start = 0;
/**
* End at string
* @var string
*/
$end = "";
// Set query params based on request params
if ($request->has('limit')) {
$limit = $request->get('limit');
}
if ($request->has('start')) {
$start = $request->get('start');
}
if ($request->has('end')) {
$end = "&end=" . $request->get('end');
}
try {
$thingsee = new \Thingsee\ThingseeAPI();
} catch (\GuzzleHttp\Exception\ClientException $e) {
dd($e);
}
// Return events in json
return $thingsee->getEvents($device, "?senses=0x00060100,0x00060200,0x00060400,0x00060300&limit=" . $limit . "&start=" . $start . $end);
}
示例5: agendaJson
public function agendaJson(Request $request)
{
// load of actions between start and stop provided by calendar js
if ($request->has('start') && $request->has('end')) {
$actions = \App\Action::with('group')->where('start', '>', Carbon::parse($request->get('start')))->where('stop', '<', Carbon::parse($request->get('end')))->orderBy('start', 'asc')->get();
} else {
$actions = \App\Action::with('group')->orderBy('start', 'asc')->get();
}
$event = '';
$events = '';
foreach ($actions as $action) {
$event['id'] = $action->id;
$event['title'] = $action->name;
$event['description'] = $action->body . ' <br/> ' . $action->location;
$event['body'] = filter($action->body);
$event['summary'] = summary($action->body);
$event['location'] = $action->location;
$event['start'] = $action->start->toIso8601String();
$event['end'] = $action->stop->toIso8601String();
$event['url'] = action('ActionController@show', [$action->group->id, $action->id]);
$event['group_url'] = action('ActionController@index', [$action->group->id]);
$event['group_name'] = $action->group->name;
$event['color'] = $action->group->color();
$events[] = $event;
}
return $events;
}
示例6: addToCart
public function addToCart(Request $request)
{
$id = $request->has('id') ? $request->input('id') : 0;
$quantity = $request->has('quantity') && $request->input('quantity') > 0 ? $request->input('quantity') : 0;
$product = Product::where(['id' => $id, 'active' => 1])->first();
if (null === $product) {
return response()->json(false);
}
$cart = $this->getCart($request);
if (!array_key_exists($id, $cart) && $quantity > 0) {
$cart[$id] = $quantity;
} elseif ($quantity > 0) {
$cart[$id] += $quantity;
}
$request->session()->put('cart', $cart);
// return product info
$product = Product::find($id);
if (sizeof($product->images) > 0 && is_file("images/{$product->images[0]->image}")) {
$image = "images/{$product->images[0]->image}";
} else {
$image = 'images/noImage.jpg';
}
$pro = array('id' => $id, 'name' => $product->name, 'qty' => $cart[$id], 'url' => url("{$id}/{$product->alias}"), 'image' => url($image), 'price' => $product->price);
$cart_data = $this->getCartData($cart);
return response()->json(['product' => $pro, 'items' => $cart_data['items'], 'total' => $cart_data['total'], 'cart_url' => url('cart')]);
}
示例7: index
/**
* Display a listing of the resource.
* @return Response
*/
public function index(Request $request)
{
$posts = CommunityPost::select('community_posts.id', 'community_posts.subject', 'community_posts.content', 'community_posts.created_at', 'community_posts.owner_type', 'community_posts.owner_id')->selectRaw("CASE community_posts.owner_type WHEN 'students' THEN 'student' END as type, COUNT(cp.id) as totalReplies")->whereNull('community_posts.parent_id')->leftJoin('community_posts as cp', 'cp.parent_id', '=', 'community_posts.id')->groupBy('community_posts.id')->with(['likes', 'replies', 'replies.owner', 'owner' => function ($query) {
return $query->select('name', 'id');
}])->join('students', function ($query) {
$query->on('students.id', '=', 'community_posts.owner_id')->where('students.gender', '=', $this->student->gender);
});
// ->groupBy('community_posts.id');
if ($request->has('postable')) {
switch ($request->input('postable')) {
case 'element':
$posts->where('community_posts.postable_type', 'subject_elements')->where('community_posts.postable_id', $request->input('id'));
break;
default:
$posts->whereNull('community_posts.postable_id');
break;
}
}
if ($request->has('my')) {
$posts->where('community_posts.owner_id', $this->student->id)->where('community_posts.owner_type', 'students');
}
if ($request->has('query')) {
$posts->where('community_posts.subject', 'LIKE', '%' . $request->input('query') . '%');
}
$posts->orderBy('community_posts.' . $request->input('orderBy', 'id'), 'DESC');
$posts = $posts->paginate(10);
foreach ($posts as $post) {
$post->old = $post->replies->sum(function ($reply) {
return $reply->created_at->diffInMonths(\Carbon\Carbon::now());
});
}
return response()->json($posts, 200, [], JSON_NUMERIC_CHECK);
}
示例8: __get
/**
* Fetch properties from the request.
*
* @param string $property
*
* @return array|string
*/
public function __get($property)
{
if ($this->request->has($property)) {
return $this->request->input($property);
}
return false;
}
示例9: update
/**
* UPDATE /api/favouritesTransactions/{favouriteTransactions}
* @param Request $request
* @param FavouriteTransaction $favourite
* @return Response
*/
public function update(Request $request, FavouriteTransaction $favourite)
{
// Create an array with the new fields merged
$data = array_compare($favourite->toArray(), $request->only(['name', 'type', 'description', 'merchant', 'total']));
$favourite->update($data);
if ($request->has('account_id')) {
$favourite->account()->associate(Account::findOrFail($request->get('account_id')));
$favourite->fromAccount()->dissociate();
$favourite->toAccount()->dissociate();
$favourite->save();
}
if ($request->has('from_account_id')) {
$favourite->fromAccount()->associate(Account::findOrFail($request->get('from_account_id')));
$favourite->account()->dissociate();
$favourite->save();
}
if ($request->has('to_account_id')) {
$favourite->toAccount()->associate(Account::findOrFail($request->get('to_account_id')));
$favourite->account()->dissociate();
$favourite->save();
}
if ($request->has('budget_ids')) {
$favourite->budgets()->sync($request->get('budget_ids'));
}
$favourite = $this->transform($this->createItem($favourite, new FavouriteTransactionTransformer()))['data'];
return response($favourite, Response::HTTP_OK);
}
示例10: index
public function index(Request $request)
{
$args = ['orderby' => $request->has('orderby') ? $request->get('orderby') : 'created_at', 'order' => $request->has('order') ? $request->get('order') : 'desc', 'key' => $request->has('key') ? $request->get('key') : null, 'parent' => $request->has('parent') ? $request->get('parent') : null];
$items = $this->province->all(current_lang(), $args);
$data = ['title' => 'Quốc gia', 'items' => $items, 'countries' => $this->country->listAll(true, current_lang())];
return view('backend.province.index', $data);
}
示例11: processDataOfBirth
/**
* @return array
*/
public function processDataOfBirth()
{
// Get the date of birth that the user submitted
$dob = null;
if ($this->request->has('dob')) {
// field name is dob when using input type date
$dob = $this->request->get('dob');
} elseif ($this->request->has('dob_year') && $this->request->has('dob_month') && $this->request->has('dob_day')) {
// field name has _year, _month and _day components if input type select
$dob = $this->request->get('dob_year') . '-' . $this->request->get('dob_month') . '-' . $this->request->get('dob_day');
}
$remember_me = false;
if ($this->request->get('remember_me') == "on") {
$this->session->set('remembered_day', $this->request->get('dob_day'));
$this->session->set('remembered_month', $this->request->get('dob_month'));
$this->session->set('remembered_year', $this->request->get('dob_year'));
$this->session->set('remember_me', "on");
$remember_me = true;
} else {
$this->session->remove('remembered_day');
$this->session->remove('remembered_month');
$this->session->remove('remembered_year');
$this->session->remove('remember_me');
}
// return in an array for validator
return ['dob' => $dob, 'remember' => $remember_me];
}
示例12: retrieve
public function retrieve(Request $request, Weather $weather)
{
if (!$request->has('lat') || !$request->has('lon')) {
return response('Please provide a lat and lon', 400);
}
$input = $request->all();
// We grab the lat and lon
$lat = $input['lat'];
$lon = $input['lon'];
// We grab the latest data from this lat and long
$rawData = file_get_contents('http://api.openweathermap.org/data/2.5/weather?lat=' . $lat . '&lon=' . $lon);
if (!$rawData) {
// We failed to retrieve data from the webservice
// Just return the stuff we have
return $weather->where('lat', $lat)->where('lon', $lon)->limit(10)->get();
}
$jsonData = json_decode($rawData, true);
// We transform this data
$data = ['dt' => $jsonData['dt'], 'lat' => $lat, 'lon' => $lon, 'type' => $jsonData['weather'][0]['main'], 'temp' => $jsonData['main']['temp'] - 273.15];
// Check if we already have a record with same lat/lon and dt in our database
$weatherCheck = $weather->where('lat', $lat)->where('lon', $lon)->where('dt', Carbon::createFromTimeStamp($data['dt']))->limit(1)->get();
// Record isn't in our db yet
if ($weatherCheck->isEmpty()) {
// We store the data in our database
$weather->create($data);
}
// We grab the last 10 weather report from given lat/lon and return it
return $weather->where('lat', $lat)->where('lon', $lon)->limit(10)->get();
}
示例13: getCartList
public function getCartList(Request $request)
{
if (!$request->has('uid')) {
return response()->json(Message::setResponseInfo('PARAMETER_ERROR'));
}
$page = $request->get('page', 1);
$uid = $request->get('uid');
$sid = 0;
if ($request->has('sid')) {
$sid = $request->get('sid');
}
$totalNum = $this->_model->getCartTolalNum($uid, $sid);
$pagedata = $this->getPageData($page, $this->_length, $totalNum);
$this->_response['page'] = $pagedata;
if ($totalNum <= 0) {
return response()->json(Message::setResponseInfo('DATA_EMPTY'));
}
$list = $this->_model->getCartList($uid, $sid, $pagedata->offset, $this->_length);
if ($list) {
$this->_response['cart'] = $list;
return response()->json(Message::setResponseInfo('SUCCESS', $this->_response));
} else {
return response()->json(Message::setResponseInfo('FAILED'));
}
}
示例14: updateProfile
public function updateProfile(Request $request)
{
$user = User::find(Auth::user()->id);
if ($request->has('first')) {
$user->first = $request->input('first');
}
if ($request->has('last')) {
$user->last = $request->input('last');
}
if ($request->has('email')) {
$user->email = $request->input('email');
}
if ($request->has('phone')) {
$user->phone = $request->input('phone');
}
if ($request->hasFile('resume')) {
$request->file('resume')->move(public_path('resumes'), $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('resume')->getClientOriginalExtension());
$user->resume = '/resumes/' . $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('resume')->getClientOriginalExtension();
}
if ($request->hasFile('headshot')) {
$request->file('headshot')->move(public_path('headshots'), $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('headshot')->getClientOriginalExtension());
$user->headshot = '/headshots/' . $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('headshot')->getClientOriginalExtension();
}
$user->save();
$request->session()->flash('success', 'Profile Updated!');
return view('editProfile', ['user' => $user]);
}
示例15: browse
public function browse(Request $request, $category = null)
{
// get categories
$categories = Category::orderBy('id', 'desc')->get();
// get jobs
if ($category != null) {
$cat = Category::where('name', '=', $category)->first();
$jobs = $cat->jobs;
} else {
$jobs = Jobs::query();
// set condition category
if ($request->has('category')) {
$cat = Category::where('name', '=', $request->get('category'))->first();
$jobs = $cat->jobs();
}
// set condition state
if ($request->has('state')) {
$jobs->where('state', '=', $request->get('state'));
}
// set condition keywords
if ($request->has('keywords')) {
$searchWords = explode(' ', $request->get('keywords'));
foreach ($searchWords as $word) {
$jobs->orWhere('description', 'LIKE', '%' . $word . '%');
}
}
$jobs = $jobs->orderBy('id', 'desc')->get();
}
return view('jobs.browse')->with('jobs', $jobs)->with('jobsCount', Jobs::count())->with('categories', $categories);
}