本文整理汇总了PHP中Illuminate\Http\Request::isMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isMethod方法的具体用法?PHP Request::isMethod怎么用?PHP Request::isMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Http\Request
的用法示例。
在下文中一共展示了Request::isMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: news
public function news(Request $request)
{
if ($request->isMethod('POST')) {
// News::create($request->except('_token'));
// read image from temporary file
$file = $request->file('imagePrev');
$img = Image::make($file->getRealPath());
$nameFile = $file->getClientOriginalName();
// resize image
$img->fit(263, 263);
// save image
$img->save("images/" . $nameFile);
News::create(['text' => $request->input('editor1'), 'header' => $request->input('header'), 'picture' => "images/" . $nameFile]);
// switch ( $request->input('type') ) {
// case 'insert':
// News::create($request->except('_token'));
// break;
// case 'update':
// News::find( $request->input('id') )->update([
// 'header' => $request->input('header'),
// 'text' => $request->input('editor1'),
// ]);
// break;
// }
}
if ($request->isMethod('GET')) {
$item = News::find($request->input('remove'));
if ($item) {
$item->delete();
}
}
$news = News::orderBy('created_at', 'DESC')->paginate(15);
return view('admin/news', ['news' => $news]);
}
示例2: update
/**
* @param Request $request
* this is the function where update the shopping cart and mainly consider about the change the quantity and display the total amount
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function update(Request $request)
{
if ($request->isMethod('post')) {
if ($request->get('UpdateCart')) {
$data = $request->session()->get('items');
$request->session()->pull('items');
foreach ($data as $item) {
$quantity = $request->get($item['id'] . 'quantity');
$request->session()->push('items', ['id' => $item['id'], 'quantity' => $quantity, 'name' => $item['name'], 'price' => $item['price'], 'imgpath' => $item['imgpath']]);
}
$data = $request->session()->get('items');
$cat_name = $request->get('catName');
return view('pages.cart.cart', compact('data', 'cart', 'total', 'n', 'cat_name'));
}
}
//this is the remove item from shoiing cart
if ($request->isMethod('post')) {
if ($request->get('cartDestroy')) {
$data = $request->session()->get('items');
$item_id = $request->get('cartDestroy');
//first pull product details from the session array
$request->session()->pull('items');
foreach ($data as $item) {
if ($item['id'] != $item_id) {
$request->session()->push('items', ['id' => $item['id'], 'quantity' => $item['quantity'], 'name' => $item['name'], 'price' => $item['price'], 'imgpath' => $item['imgpath']]);
}
}
$data = $request->session()->get('items');
$cat_name = $request->get('catName');
return view('pages.cart.cart', compact('data', 'cat_name'));
}
}
}
示例3: anyUpload
public function anyUpload(InterfaceFileStorage $userFileStorage, AmqpWrapper $amqpWrapper, Server $server, UploadEntity $uploadEntity)
{
/* @var \App\Components\UserFileStorage $userFileStorage */
$responseVariables = ['uploadStatus' => false, 'storageErrors' => [], 'uploadEntities' => []];
if ($this->request->isMethod('post') && $this->request->hasFile('file') && $this->request->file('file')->isValid()) {
$tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-user-files-to-storage' . DIRECTORY_SEPARATOR;
$tmpFilePath = $tmpDir . $this->request->file('file')->getClientOriginalName();
$this->request->file('file')->move($tmpDir, $this->request->file('file')->getClientOriginalName());
$userFileStorage->setValidationRules($this->config->get('storage.userfile.validation'));
$newStorageFile = $userFileStorage->addFile($tmpFilePath);
if ($newStorageFile && !$userFileStorage->hasErrors()) {
/* @var \SplFileInfo $newStorageFile */
// AMQP send $newfile, to servers
foreach ($server->all() as $server) {
if (count($server->configs) > 0) {
foreach ($server->configs as $config) {
// Send server and file info to upload queue task
$amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $config->auth . '@' . $server->host . '/' . trim($config->path, '\\/')]));
}
} else {
// The server has no configuration
$amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $server->host]));
}
}
$responseVariables['uploadStatus'] = true;
} else {
$responseVariables['storageErrors'] = $userFileStorage->getErrors();
}
if ($this->request->ajax()) {
return $this->response->json($responseVariables);
}
}
$responseVariables['uploadEntities'] = $uploadEntity->limit(self::UPLOAD_ENTITIES_LIMIT)->orderBy('created_at', 'DESC')->get();
return $this->view->make('upload.index', $responseVariables);
}
示例4: execute
/**
* {@inheritdoc}
*/
public function execute($request)
{
/** @var $request ObtainCreditCard */
if (false == $this->supports($request)) {
throw RequestNotSupportedException::createActionNotSupported($this, $request);
}
if ($this->request->isMethod('POST')) {
$creditCard = new CreditCard();
$creditCard->setHolder($this->request->get('card_holder'));
$creditCard->setNumber($this->request->get('card_number'));
$creditCard->setSecurityCode($this->request->get('card_cvv'));
$creditCard->setExpireAt(new DateTime($this->request->get('card_expire_at')));
$request->set($creditCard);
return;
}
$form = $this->viewFactory->make($this->templateName, ['model' => $request->getModel(), 'firstModel' => $request->getFirstModel(), 'actionUrl' => $request->getToken() ? $request->getToken()->getTargetUrl() : null]);
throw new HttpResponse(new Response($form->render(), 200, ['Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'X-Status-Code' => 200, 'Pragma' => 'no-cache']));
/*
$content = $this->viewFactory->make($this->templateName, [
'model' => $request->getModel(),
'firstModel' => $request->getFirstModel(),
'form' => $form->render(),
'actionUrl' => $request->getToken() ? $request->getToken()->getTargetUrl() : null,
]);
$this->gateway->execute($renderTemplate);
throw new HttpResponse(new Response($renderTemplate->getResult(), 200, [
'Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0',
'X-Status-Code' => 200,
'Pragma' => 'no-cache',
]));
*/
}
示例5: contact
/**
* Create simple contact form
* @return void
*/
public function contact(Request $request)
{
if ($request->isMethod('get')) {
return view('pages.contact');
} elseif ($request->isMethod('post')) {
dd($request->all());
}
}
示例6: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->isMethod('POST') || $request->isMethod('PUT')) {
json_decode($request->getContent());
if (json_last_error() != JSON_ERROR_NONE) {
return response()->json("Request must be json", 400);
}
}
return $next($request);
}
示例7: correctSlug
/**
* @param \Illuminate\Http\Request $request
*/
protected function correctSlug(&$request)
{
$slug = $request->input('slug');
$validateMethod = $request->isMethod('POST') || $request->isMethod('PUT') || $request->isMethod('PATCH');
if (!empty($slug) && $validateMethod) {
$strSlug = Str::slug($slug);
if ($strSlug !== $slug) {
$request->request->set('slug', $strSlug);
}
}
}
示例8: update
public function update(Request $request, $id)
{
if ($request->isMethod('get')) {
$data['item'] = Bahan::find($id);
return view('update', $data);
} elseif ($request->isMethod('post')) {
$item = Bahan::find($id);
$item->nama = Input::get('nama');
$item->kode = Input::get('kode');
$item->save();
return redirect('bahan');
}
}
示例9: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(\Illuminate\Http\Request $request)
{
// validation rule for create request.
if ($request->isMethod('POST')) {
return ['name' => 'required', 'content' => 'required'];
}
// Validation rule for update request.
if ($request->isMethod('PUT') || $request->isMethod('PATCH')) {
return ['name' => 'required'];
}
// Default validation rule.
return [];
}
示例10: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(Request $request)
{
if ($request->isMethod('POST')) {
// validation rule for create request.
return [];
}
if ($request->isMethod('PUT') || $request->isMethod('PATCH')) {
// Validation rule for update request.
return [];
}
// Default validation rule.
return [];
}
示例11: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(\Illuminate\Http\Request $request)
{
$user = $this->route('user');
// validation rule for create request.
if ($request->isMethod('POST')) {
return ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6'];
}
// Validation rule for update request.
if ($request->isMethod('PUT') || $request->isMethod('PATCH')) {
return ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users,email,' . $user->id];
}
// Default validation rule.
return [];
}
示例12: rules
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(\Illuminate\Http\Request $request)
{
$role = $this->route('role');
// validation rule for create request.
if ($request->isMethod('POST')) {
return ['name' => 'required|max:50|unique:roles'];
}
// Validation rule for update request.
if ($request->isMethod('PUT') || $request->isMethod('PATCH')) {
return [];
}
// Default validation rule.
return [];
}
示例13: update
public function update(Request $request, $id)
{
if ($request->isMethod('get')) {
$data['item'] = Resep::find($id);
$data['kokis'] = Koki::all();
return view('resep.update', $data);
} elseif ($request->isMethod('post')) {
$item = Resep::find($id);
$item->nama = Input::get('nama');
$item->kode = Input::get('kode');
$item->koki_id = Input::get('koki_id');
$item->save();
return redirect('resep');
}
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
//Log::info('$request=<' . $request . '>');
if ($request->isMethod('post')) {
$bodyContent = $request->getContent();
//Log::info('$bodyContent=<' . $bodyContent . '>');
$bodyJson = json_decode($bodyContent);
$keyPath = $this->keyRoot_ . $bodyJson->token . '/pubKey.pem';
$fp = fopen($keyPath, 'r');
$pubKeyMem = fread($fp, 8192);
fclose($fp);
$pubkeyid = openssl_pkey_get_public($pubKeyMem);
$token = $bodyJson->token;
$sign = $bodyJson->sign;
$ok = openssl_verify($token, hex2bin($sign), $pubkeyid, "sha256");
openssl_free_key($pubkeyid);
if ($ok == 1) {
$profilePath = $this->keyRoot_ . $bodyJson->token . '/profile';
//Log::info('$bodyJson->payload=<' . json_encode($bodyJson->payload) . '>');
file_put_contents($profilePath, json_encode($bodyJson->payload));
return response()->json(['status' => 'success']);
} else {
return response()->json(['status' => 'failure']);
}
}
}
示例15: reportsAction
public function reportsAction(Request $request)
{
$users = DB::select('select id, first_name, last_name, email from users');
if ($request->isMethod('post')) {
$id = substr($request->input('email'), strpos($request->input('email'), ":") + 2);
$year = $request->input('year');
$month = $request->input('month');
$events = DB::select('select users.first_name, events.*, transport.name as t_name, transport.load_consumption,
transport.moving_consumption, transport.stat_consumption
from users inner join events on users.id = events.user_id
left join transport on events.vehicle_id = transport.id
where year(events.date) = ? and month(events.date) = ?
AND users.id = ?', [$year, $month, $id]);
$calc = [];
foreach ($events as $event) {
$parsed_arrive = date_parse($event->client_arrive);
$parsed_leave = date_parse($event->client_leave);
$hours['arrive'] = $parsed_arrive['hour'] + $parsed_arrive['minute'] / 60;
$hours['leave'] = $parsed_leave['hour'] + $parsed_leave['minute'] / 60;
$hours['actual'] = $hours['leave'] - $hours['arrive'] - $event->min_spent / 60;
$calc[$event->id]['distance'] = (int) $event->spidometer_finish - (int) $event->spidometer_start;
$calc[$event->id]['fuel'] = $calc[$event->id]['distance'] / 100 * $event->moving_consumption + $event->min_spent / 60 * $event->load_consumption + $hours['actual'] * $event->stat_consumption;
}
// die(var_dump($calc));
return view('admin/reports', ['events' => $events, 'calc' => $calc, 'users' => $users]);
}
return view('admin/reports', ['users' => $users]);
}