---
# System prepended metadata

title: laravel request & response
tags: [laravel]

---

# laravel request & response 

###### tags: `laravel`


### 移除request的特定input
https://stackoverflow.com/questions/35327679/validate-or-remove-for-extra-fields-in-laravel

```php!

if(!$request->input('img')==null){
    $request->request->remove('img');
}

```





### (laravel5.8)如何針對不同request回傳不同response
https://stackoverflow.com/questions/42815196/how-to-return-different-output-formats-from-the-same-controller-method-in-larave

```php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Todo;

class TodosController extends Controller
{
    //...


    public function show($id, Request $req)
    {
        $todo = Todo::find($id);
        
        // If the request has header `Accept: */json`, return JSON
        if ($req->wantsJson()) {
            return $todo;
        }
        
        // Otherwise, return view
        return view('show', ['todo' => $todo]);
    }
//...
 
}

```