2,970 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to 404 For Www.a.com And A.com When Using Domain
Hi @sophieye
You can do this with httaccess, https://htaccessbook.com/htaccess-redirect-https-www/
Replied to Can't Upload Repository To Github
Hi @desssha
already visited this page? https://docs.github.com/en/github/authenticating-to-github/error-permission-denied-publickey
Replied to Error With Abstract Metho
The error tells you already what is wrong Class App\Exports\ ItemsSaleExcel contains 1 abstract method and must therefore be declared abstract or implement the remaining methods
And it gives you the missing method as well, collection
So you know there is something wrong with collection
Awarded Best Reply on Error With Abstract Metho
Hi @swimmer
You are missing the collection
method in your ItemsSaleExcel
class.
But I think it is a typo?
public function collectio ()
{
$items_info = collect($this->links_with_sale);
// $items_info = $items_info->only(['SKU', 'tradesy_sku']);
return $items_info;
}
Missing the 'n' in your method collectio
instead of collection
Replied to Error With Abstract Metho
Hi @swimmer
You are missing the collection
method in your ItemsSaleExcel
class.
But I think it is a typo?
public function collectio ()
{
$items_info = collect($this->links_with_sale);
// $items_info = $items_info->only(['SKU', 'tradesy_sku']);
return $items_info;
}
Missing the 'n' in your method collectio
instead of collection
Awarded Best Reply on Remove 'CMP/' From A HUGE Array
Hi @jgravois
Try preg_replace()
preg_replace — Perform a regular expression search and replace
https://www.php.net/manual/en/function.preg-replace.php
$output = preg_replace("/(CMP/)(.+)/", "$2", $input);
Attention: The code highlight below removes the $2 in the replacement :/
<?php
$input= [
"CMP/452",
"CMP/47",
"CMP/A117"
];
var_dump(preg_replace("/(CMP\/)(.+)/", "", $input));
/*
array(3) {
[0]=>
string(3) "452"
[1]=>
string(2) "47"
[2]=>
string(4) "A117"
}
*/
?>
Replied to Remove 'CMP/' From A HUGE Array
Hi @jgravois
Try preg_replace()
preg_replace — Perform a regular expression search and replace
https://www.php.net/manual/en/function.preg-replace.php
$output = preg_replace("/(CMP/)(.+)/", "$2", $input);
Attention: The code highlight below removes the $2 in the replacement :/
<?php
$input= [
"CMP/452",
"CMP/47",
"CMP/A117"
];
var_dump(preg_replace("/(CMP\/)(.+)/", "", $input));
/*
array(3) {
[0]=>
string(3) "452"
[1]=>
string(2) "47"
[2]=>
string(4) "A117"
}
*/
?>
Replied to Blade Component Issue
hi @ehsan bagherzadegan
Somewhere in Blade you are calling your component but you don't add the for
variable I guess?
You need something like:
<x-error for="your for value"></x-error>
Awarded Best Reply on Laravel Rule To Pass If Value Is Either Hostname Or IP
Hi @mathewparet
You don't have to write a regex, PHP has already has a (filter_var) function for this.
private function isValidIP($value)
return filter_var($value, FILTER_VALIDATE_IP) !== false;
}
https://www.w3schools.com/php/filter_validate_ip.asp
Laravel does the same in the IP validation, vendor\laravel\framework\src\Illuminate\Validation\Concerns\ValidatesAttributes.php
/**
* Validate that an attribute is a valid IP.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function validateIp($attribute, $value)
{
return filter_var($value, FILTER_VALIDATE_IP) !== false;
}
Replied to Laravel Rule To Pass If Value Is Either Hostname Or IP
Hi @mathewparet
You don't have to write a regex, PHP has already has a (filter_var) function for this.
private function isValidIP($value)
return filter_var($value, FILTER_VALIDATE_IP) !== false;
}
https://www.w3schools.com/php/filter_validate_ip.asp
Laravel does the same in the IP validation, vendor\laravel\framework\src\Illuminate\Validation\Concerns\ValidatesAttributes.php
/**
* Validate that an attribute is a valid IP.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function validateIp($attribute, $value)
{
return filter_var($value, FILTER_VALIDATE_IP) !== false;
}
Replied to Payload Column In Sessions Table
Hi @uniqueginun
It stores the encoded(base64_encode) data from a session.
Example
$request->session()->put('key', 'value');
value
(and some more info as user ID and the current timestamp) will be encoded stored in the payload column.
Awarded Best Reply on File(docx,pdf) And Image(jpeg,png Etc..) Support Validation Laravel
Hi @neeraj1005
Image
The file under validation must be an image (jpg, jpeg, png, bmp, gif, svg, or webp).
https://laravel.com/docs/8.x/validation#rule-image
You can use a MIME Rule and add the validation mime types from the image validation.
$validatedData = $this->validate([
'product_name' => 'required',
'images.*' => 'mimes:jpg,jpeg,png,bmp,gif,svg,webp,pdf,docx|max:1024',
]);
https://laravel.com/docs/8.x/validation#basic-usage-of-mime-rule
Replied to File(docx,pdf) And Image(jpeg,png Etc..) Support Validation Laravel
Yes, remove the image rule.
Replied to File(docx,pdf) And Image(jpeg,png Etc..) Support Validation Laravel
Hi @neeraj1005
Image
The file under validation must be an image (jpg, jpeg, png, bmp, gif, svg, or webp).
https://laravel.com/docs/8.x/validation#rule-image
You can use a MIME Rule and add the validation mime types from the image validation.
$validatedData = $this->validate([
'product_name' => 'required',
'images.*' => 'mimes:jpg,jpeg,png,bmp,gif,svg,webp,pdf,docx|max:1024',
]);
https://laravel.com/docs/8.x/validation#basic-usage-of-mime-rule
Awarded Best Reply on How To Delete Files On Download Cancellation
Hi @daenufrey
I make use of ZipArchive
and this is doing what you want to do.
https://www.php.net/manual/en/class.ziparchive.php
Here is an example
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//Add image
foreach($images as $files) {
$zip->addFile($file_path.$files,$files);
}
$zip->close();
//then send the headers to force download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
// remove zip
unlink($archive_file_name);
exit;
I did not use Laravel for this code above, so maybe you can look to streamDownload
in Laravel
https://laravel.com/docs/7.x/responses#file-downloads
Sometimes you may wish to turn the string response of a given operation into a downloadable response without having to write the contents of the operation to disk. You may use the streamDownload method in this scenario. This method accepts a callback, file name, and an optional array of headers as its arguments
Replied to Laravel 8 Vuejs Image Doesn't Upload And Save To Database
@rod2rick no errors in the logs?
Your upload code looks fine.
Did you set some dumps/dd
code in your upload code for debugging?
Example:
if ($request->hasfile('image')) {
dump('has file');
$image = $request->file('image');
$filename = $produit->nom . '_' . time() . '.' . $image->getClientOriginalExtension();
if ($produit->image && $produit->image == 'noproductimage.jpg') {
dump('in if');
Image::make($image)->resize(500, 500)->save(public_path('/uploads/produits/' . $filename));
} else {
dump('in else');
File::delete(public_path('/uploads/produits/' . $produit->image));
Image::make($image)->resize(500, 500)->save(public_path('/uploads/produits/' . $filename));
}
$produit->image = $filename;
}
dd('end debugging');
Replied to Laravel 8 Vuejs Image Doesn't Upload And Save To Database
Hi @rod2rick
Add
headers: {
'Content-Type': 'multipart/form-data'
}
In your Axios request
axios.post("/api/createproduit", {
nom: this.nom,
description: this.description,
image: this.image,
}, headers: {
'Content-Type': 'multipart/form-data'
})
.then((response) => {
this.produits = response.data.data;
this.loading = false;
....
....
Or
let formData = new FormData();
formData.append('file', this.image);
this.axios.post('/api/createproduit',
formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
}
.....
Awarded Best Reply on Eloquent Make Exists Return True
You can use exists()
on queries, $post = Post::make();
is not a query, with this code you are only creating and returning an un-saved model instance.
Replied to Eloquent Make Exists Return True
You can use exists()
on queries, $post = Post::make();
is not a query, with this code you are only creating and returning an un-saved model instance.
Replied to Get All Data From Two Tables
Hi @maltekiefer
foreach($mail as $id){
dd($id->communicationtypeCompanies);
dd($id->communicationtypeContacts);
}
Replied to Livewire Nested Component Not Working
Hi @adgower
What if you add a Listener?
<?php
namespace App\Http\Livewire\Todos;
use Livewire\Component;
class TodoShow extends Component
{
public $todo;
protected $listeners = ['render' => 'render'];
public function render()
{
return view('livewire.todos.todo-show');
}
}
Replied to Anonymous Component Props Always Equal To Default Value
@ignium thanks!
Already tried to recreate input.blade.php
step by step?
I don't have Livewire installed on this machine but tried to reproduce your code without Livewire. This is working.
input.blade.php
@props([
'prepend' => null,
'append' => null,
'type' => 'text'
])
<div class="{{ $attributes->get('class') }}">
<label for="test-input" class="block text-sm font-medium leading-5 text-gray-700">{{ $slot }}</label>
<input
{{ $attributes->except('class') }}
id="test-input"
type="{{ $type }}"
data-lpignore="true"
class="form-input block w-full sm:text-sm sm:leading-5 {{ $prepend ? 'pl-7' : '' }} {{ $append ? 'pr-12' : '' }} disabled:bg-gray-100"
/>
@if($append)
<div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
<span class="text-gray-500 sm:text-sm sm:leading-5" id="price-currency">
{{ $append }}
</span>
</div>
@endif
</div>
and
<x-input
wire:model.lazy="initial_payment"
min="0"
step="0.01"
type="number"
prepend="$"
placeholder="placeholder....."
class="col-span-6 sm:col-span-3"
>field name</x-input>
Awarded Best Reply on Real Time Validation Of Nested Object Fails
And removing the space?
'user.badge' => 'required|unique:users, badge',
to
'user.badge' => 'required|unique:users,badge',
?
Replied to Real Time Validation Of Nested Object Fails
And removing the space?
'user.badge' => 'required|unique:users, badge',
to
'user.badge' => 'required|unique:users,badge',
?
Replied to Anonymous Component Props Always Equal To Default Value
Hi @ignium
Can you post the full input.blade.php
file?
Replied to Real Time Validation Of Nested Object Fails
hi @jgravois
You can also add the column name in the validation
'user.badge' => 'required|unique:users, badge',
Replied to Livewire Error On Form - Freezing Screen
Error in your code?
<input type="password" class="form-control" wire:model=" name"wire:model="password" required>
Awarded Best Reply on TEMPORARY Table In Laravel
@araw I think this is the case
php artisan migrate
(for the first time to create the table) and create the table temp_data
, the table exists.temporary_check
for the first time everything is still workingtemporary_check
you also drop the table temp_data
so the next time you run temporary_check
the table does not exist and you will get this error.So you need somewhere recreate the temp_data
table.
Another option is to don't drop the table (Schema::drop('temp_data');
) but remove all the data inside this table (DB::table('temp_data')->truncate();
) so the table keeps existing.
Replied to TEMPORARY Table In Laravel
@araw I think this is the case
php artisan migrate
(for the first time to create the table) and create the table temp_data
, the table exists.temporary_check
for the first time everything is still workingtemporary_check
you also drop the table temp_data
so the next time you run temporary_check
the table does not exist and you will get this error.So you need somewhere recreate the temp_data
table.
Another option is to don't drop the table (Schema::drop('temp_data');
) but remove all the data inside this table (DB::table('temp_data')->truncate();
) so the table keeps existing.
Replied to TEMPORARY Table In Laravel
Do you have a GUI tool voor your database? Like PHPmyadmin for example and can you see the table temp_data
?
Replied to TEMPORARY Table In Laravel
And you also fired php artisan migrate
?
You drop table in the code Schema::drop('temp_data');
. Do you run the check temporary_check
multiple times?
Can you give us the output of
...
public function temporary_check()
{
DB::table('temp_data')->insert(['sender_id'=>2,'receiver_id'=>3,'message'=>'message temp check']);
$data = DB::table('temp_data')->get();
dd($data);
Schema::drop('temp_data');
return $data;
}
Still the same error
Replied to TEMPORARY Table In Laravel
Hi @araw
But in this piece of code you don't create the table. Did you create the temp table somewhere?
Replied to How To Upload Multiple Image In A Single Row?
Not tested but something like this?
if($request->hasFile('files')){
$counter = 0;
$project = [
'project_name' => $addProjectName,
'project_des' => $addProjectDes,
'project_link' => $addProjectLink
];
$host = $_SERVER['HTTP_HOST'];
foreach ($request->file('files') as $file) {
$files = $file->store('public');
$fileName = (explode('/',$files))[1];
$projectImage = 'http://'.$host.'/storage/'.$fileName;
if (!$counter) {
$project['project_image'] = $projectImage;
}
else {
$project['project_image' . $counter] = $projectImage
}
$counter++;
}
DB::table('projects')->insert($project);
}