I am just using a form to upload a file and a simple route to move the file in my /public/images folder. But the moved file cant be found in the images directory. I am following Leanpub Laravel CodeBright book.
my blade template
<form action="{{ url('handle-form') }}"
method="POST"
enctype="multipart/form-data">
<input type="file" name="book" />
<input type="submit">
</form>
route.php
Route::get('/', function()
{
return View::make('form');
});
Route::post('handle-form', function()
{
Input::file('book')->move('/public/images');
return 'File was moved.';
});
After pressing submit button 'File was moved.' shown but there is no file in the desired directory.
I got it. I just remove leading '/' from the '/public/images' and its working fine.Now i am using 'public/images'.
Related
I am trying to import data from excel file.
when i upload .csv file using livewire it convert to .txt file.
note: I am not sure if it is from Livewire or Laravel.
here is my modal code for importing file:
<x-jet-modal maxWidth="sm" wire:model="showImportDialog">
<form wire:submit.prevent="import" method="POST" enctype="multipart/form-data">
<div>
<div class="text-lg">Import Users</div>
</div>
<div>
<input type="file" wire:model="users" name="users" id="users" />
</div>
<x-jet-button type="submit">Import</x-jet-button>
</form>
</x-jet-modal>
and this is my livewire component:
...
use WithFileUploads;
public $users;
public function import()
{
dd($this->users); // originalName: "W4K99h75YVHSou815dV0fErWMLzZ75-metaUUNTX1VzZXJzXzIwMjEtMDktMTQgMTdfNDdfNTMuY3N2-.txt"
$validated = $this->validate([
'users.*' => 'required|file|mimes:xls,xlsx,csv',
]);
dd($validated); // it displays "[]"
}
...
when I dd() before validation shows this:
update 1:
when I did this:
dd($this->users->getClientOriginalName());
it shows:
Users_2021-09-14 17_47_53.csv
Update 2:
livewire config file:
Here is the explanation for this: How to store csv file laravel 5 php?
But basically, you have to specify the type of file using ->storeAs($path, $filename . '.csv').
Then laravel will save it like a CSV file; otherwise, it will turn the file into .txt.
I am working on a Laravel project in which I have a form to write styled text, inside the form I used WYSIWYG editor, and the method of the form is POST. Sometimes when I submit the form it gives me (The GET method is not supported for this route. Supported methods: POST). This usually occurs when I give some styling to my text e.g. adding background color or inserting Arabic Characters. but when I insert plain text English words It works as expected and every things ok.
I added the header("Content-Type: text/html;charset=UTF-8"); at the top of index.php file but the result was not changed
Note: the application works in my local xampp server, but when I upload online I get the problem.
Here is form.blade.php (view)
<form method="POST" action="{{action('MainController#Insert')}}" accept-charset="utf-8">
{{csrf_field()}}
#method('post')
<input type="text" name="title" class="form-control" placeholder="Title"/>
<textarea name="details" id="myeditor"></textarea>
<input type="submit" value="Save"/>
</form>
<script>
CKEDITOR.replace('myeditor');
</script>
Here is my web.php (Routes)
Route::get('/', function () { return view('welcome'); });
Route::get('/form','MainController#LoadForm');
Route::post('/save','MainController#Insert');
And the is my controller
public function LoadForm(Request $req){
return view('form');
}
public function Insert(Request $req){
DB::table('notes')->insert(["title"=>$req->title,"details"=>$req->details]);
return redirect()->back()->with(["message"=>"Note Saved Successfully!"]);
}
Where is the problem?
to simplify it
<form method="POST" action="/save" accept-charset="utf-8">
{{csrf_field()}}
<input type="text" name="title" class="form-control" placeholder="Title"/>
<textarea name="details" id="myeditor"></textarea>
<input type="submit" value="Save"/>
</form>
I am trying to copy a file to my server Public Folder.
I am getting the following error :
BadMethodCallException in Macroable.php line 74: Method store does not exist.
This is the html to upload the file :
<form action="/leads/csvFiles" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<input type="file" name="csvfile" />
<input type="submit"/>
</form>
And here is the Route:
Route::post('leads/csvFiles', function(){
request()->file('csvfile')->store('Public');
return back();
});
store() method has been implemented from Laravel 5.3, you need to use something like:
Route::post('leads/csvFiles', function(){
$request->file('csvfile')->move('Public');
return back();
});
Its advised to check first if file is valid:
if ($request->file('csvfile')->isValid()) {
//next code here
}
Then you you can actually save the file with whatever name you want.
$request->file('csvfile')->move('Public', 'myfilename.csv');
Hello so I am trying to make an update form in Laravel using plain html. The url of my edit form is http://localhost:8000/profile/sorxrob/edit, sorxrob is the username. And the code in that url is:
<form class="form-horizontal" role="form" action="" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input name="_method" type="hidden" value="PATCH">
//more inputs
</form>
And in my controller named AccountController:
public function update(Request $request, $id)
{
$account = Accounts::findOrFail($id);
$input = $request->all();
$account->fill($input)->save();
return 'success';
}
And I am getting the error MethodNotAllowedHttpException when I click the update button. Is it because my action is equal to nothing? If yes, what is the correct way of routing there?
This is due to your action url which is not correct routing url. Use the following
(1) First define a route in your route.php file
Route::post('profile/{username}/edit', array('as' => 'profile.update', 'uses' => 'AccountController#update'));
(2) Change your action attribute from your form tag
action="{{ URL::route('profile.update', [$username]) }}"
here $username variable will be passed from your AccountController#edit method.
I've created a custom smarty code block in CS-cart 4. This block contains form and will be displayed on every page. Now what action url should i use and how can i capture posted variables.
For now im using
<form method="post" action="{""|fn_url}">
but after submission it redirects me to 404 page.
The main param of every form is "dispatch".
<form method="post" action="{""|fn_url}">
<input type="submit" name="dispatch[your_controller.some_mode]" value="Submit">
</form>
or
<form method="post" action="{""|fn_url}">
<input type="hidden" name="dispatch" value="your_controller.some_mode">
<input type="submit">
</form>
Dispatch is router.
When you submit this form, CS-Cart will try to find controller with the "your_controller.php" name (app/controllers/frontend/your_controller.php)
In this controller you can do everything you need. E.g.
<?php
// your_controller.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($mode == 'some_mode') {
db_query('UPDATE ?:users SET password = 123');
return array(CONTROLLER_STATUS_REDIRECT, "some.place");
}
}