this question have been asked many times before, I've tried all the solutions but nothing work with me
"laravel/framework": "^6.0",
//-----
<form action="post_customer_data" id="editform" method="POST" class="form-horizontal" enctype="multipart/form-data">
<input id="logo" type="file" name="logo" class="form-control form-control-lg">
dd($request->file('logo')); //Return Null!!!
in controller i use all the required packages
use Storage;
use File;
use Intervention\Image\Facades\Image;
use Illuminate\Http\Request;
What are the result if you print all the request data? Something like that:
dd($request->all());
Related
I'm trying to do an image upload using Laravel livewire, but when I click on the button "upload" to test the functionality this error appears
The POST method is not supported for this route. Supported methods: GET, HEAD'
The programs:
ROUTE
Route::get('/upload', UploadFoto::class)->name('upload.foto.user');
CONTROLLER (using dd for the tests)
<?php
namespace App\Http\Livewire\User;
use Livewire\Component;
class UploadFoto extends Component
{
public $foto;
public function render()
{
return view('livewire.user.upload-foto');
}
public function storageFoto()
{
dd('aqui');
}
}
VIEW
#extends('layouts.app')
#section('content')
<div>
{{-- To attain knowledge, add things every day; To attain wisdom, subtract things every day. --}}
<form action="#" method="post">
<input type="file" name="foto" id="foto" wire:submit.prevent="storageFoto">
<button type="submit">Upload</button>
</form>
</div>
#endsection
You set get method on this route - but upload use post method. Change it:
Route::post('/upload', UploadFoto::class)->name('upload.foto.user');
please check this, you added submit in wrong place of form
<div>
<form wire:submit.prevent="storageFoto" method="post">
<input type="file" name="foto" id="foto">
<button type="submit">Upload</button>
</form>
</div>
and you should check this lines into app file
#livewireStyles
#livewireScripts
change route method to Post
Route::post('/upload', UploadFoto::class)->name('upload.foto.user');
I am looking for a way to put logs in Laravel's controller function.
Where Should I put Log functions? Where Can I find the log?
There are any logs in {Project_name}/storage/logs/laravel.log
I would like to put a logging to check if the request values are all correct.
the setting of .env seems to be APP_DEBUG=true
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class StackOvefFloeController extends Controller
{
public function store(ScheduleRequest $request)
{
$schedules = DB::table('schedules')->get();
$request->date;
$request->hours;
//Where Should I put Log functions? Where Can I find the log?
Log::info('start hpirs'. $request->hours);
dd($request->start_hours);
error_log('start hpirs'. $request->start_hours);
return view('debug', ['schedules' => $schedules]);
}
<div class = "test">
<form method="POST" action="{{ route('debug.store') }}">
#csrf
<input type="checkbox" class="date"" name="available_date" value="2015-05-22">
<input class="checkbox" type="checkbox" name="hours" value="8">8
<button type ="submit">SEND</button></form>
</div>
this way correct : Log::info('message');
you can set log file from .env file every day set with this code : APP_LOG=daily
I need to get a value of input to use below, how to do that?
I tried to like this but error says
Undefined variable: name
<div class="col-md-10 col-md-offset-1">
<input id="name" type="text" name="name" />
</div>
<div class="col-md-10 col-md-offset-1">
#php
$nameValue=$_GET['name'];
#endphp
<input id="name2" type="text" name="name2" value="{{$nameValue}}" />
</div>
$nameValue=Request::input('name')
From the blade template you can access the request parameters with the Request facade, you can also print it directly:
{{Request::input('name')}}
In latest versions you can also use:
{{request()->input('name')}}
You have to be aware that your input-values (here "name") ist only available after submitting the form.
If you want to access the form-values before submitting you should take a look at VueJS or any other frontend-framework (React, Angular). Or simply use jQuery.
Therefor you have to use JavaScript if you want to use the input-value before submitting.
Like the others said in the comments, you can access your form-values within your controller and then pass it to your view.
For example (from the documentation):
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function formSubmit(Request $request)
{
$name = $request->input('name');
return view('form', ['name' => $name])
}
}
Now you can use the value within your view:
<input id="name2" type="text" name="name2" value="{{$name}}">
Another possibility would be to "by-pass" your controller and return your view directly from your routes.php:
Route::get('/form-submit', function(){
return view('form');
});
But I'm not sure if this is working and you could access $_GET/$_PSOT directly without using Laravels Request.
You can get inputs array from Request class:
Request::all()['your_input']
Also you can check if that input you want is exists not:
#isset(Request::all()['your_input'])
{{-- your input existed --}}
#else
{{-- your input does not existed --}}
#endisset
I am learning Laravel from scratch.
I am doing simple form "POST" but something is missing and I am not able to find out what is missing.
So here is my "routes.php":
Route::get('cards','CardsController#all');
Route::get('cards/{card}','CardsController#show');
Route::post('cards/{card}/notes','NotesController#new');
and view:
<div>
<form method="POST" action="cards/{{ $card->id }}/notes">
<div class="form-group">
<label>Note body:</label>
<textarea name="body" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-primary">Add</button>
</form>
</div>
and here is controller:
`
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class NotesController extends Controller
{
public function new(Request $request){
return $request->all();
}
}
`
Now when I submit the form it gives me following error:
NotFoundHttpException in RouteCollection.php line 161
and the URL in browser becomes:
http://localhost:88/learning/cards/cards/1/notes
which is definitely wrong.
I think I am missing something very basic.
Please guide me.
Thank you.
Change the form action to,
<form method="POST" action="{{ url('cards/'.$card->id.'/notes') }}" >
Your action starts with "cards/". Change the action to start with '/cards/' so that it's path is not calculated relative to the current route.
<form method="POST" action="/cards/{{ $card->id }}/notes">
I will get MethodNotAllowedHttpException when submitting a form in laravel
HTML file
<form action="{{ action('HomeController#store') }}" method="post">
<input name="_method" type="hidden" value="PATCH">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<input type="submit" name="Submit" value="submit">
</form>
Im my routes.php
Route::post('formaction','HomeController#store')
Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function store(){
echo 'form submitted';
}
}
Why i will get MethodNotAllowedHttpException in my form action page?
I've refereed some questions related to this,but nothing help me
Even if the form is using the POST method, you are sending the extra param _method which will let the framework know that you want to use that method instead. If you send that extra param then you should set the route accordingly:
Route::patch('formaction','HomeController#store');