2,770 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 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);
}
Replied to Getting 404 Error In Every Laravel Project After Adding A Virtual Host In Xampp.
Hi @ravish
Can you show us the whole C:/xampp/apache/conf/extra/httpd-vhosts
and C:\Windows\System32\drivers\etc\hosts
file?
Can you also give us a link to the Youtube video?
Replied to Element-ui Pagination With Table
@msslgomez you already have solved this(I see your answer as solved in your other topic) ?
Replied to Element-ui Pagination With Table
Hi @msslgomez
I never used this package but based on the documentation you need to pass the total
items (you already do this), current-page
number and page-size
, based on those variables the pagination can create the pager.
Example, you have 45 items, you want to show 10 items on a page. So you pass
Total: 45
Page-size: 10
current-page: 1
You will see something like 1 | 2 | 3 | 4 | 5
If you click on another page item, event handleCurrentChange
will triggered.
handleCurrentChange(val) {
console.log(`current page: ${val}`);
},
Based on the new current page you can do an axios request for example and getting the next/previous 10 items for in you table. I assume :data="displayData"
is the data for in el-table
?
Something like:
handleCurrentChange(val) {
axios.get("your-url-to-get-new-data?page=" + ${val})
.then(response => {
// update displayData
})
},
Replied to Admin-lte Installation And Setup Through Npm
@neeraj1005 did you already create an Blade file with only HTML / CSS / JS for datatables?
Replied to 2000 External Api Call In A Job
Hi @equimper
Now you are doing a query for each player, so yes a lot of queries.
Bulk is a good idea but Eloqent does not support bulk for updateOrCreate
Maybe you can use something like this for bulk insert https://gist.github.com/RuGa/5354e44883c7651fd15c ?
Replied to Admin-lte Installation And Setup Through Npm
Hi @neeraj1005
Are there errors in your browser console?
Replied to How To Delete Files On Download Cancellation
@automica it seems like that, if I remove the unlink
then I will (of course) see the file if I cancel it
Replied to How To Delete Files On Download Cancellation
The download popups if the zip is ready so you can't cancel the download if it is not ready. If I cancel the download when it is ready, there is no file on the server.
Replied to 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
Awarded Best Reply on Prevent Timestamps When Increment View_count
Hi @naysoewin,
You can disable the timestamps and do a save?
$post->timestamps = false;
$post->increment('view_count');
$post->save();
And you can create a kind of increment in your $post
model
public function incrementViewCount() {
$this->timestamps = false;
$this->increment('view_count');
$this->save();
}
So you can call
$post->incrementViewCount();
Replied to Prevent Timestamps When Increment View_count
Hi @naysoewin,
You can disable the timestamps and do a save?
$post->timestamps = false;
$post->increment('view_count');
$post->save();
And you can create a kind of increment in your $post
model
public function incrementViewCount() {
$this->timestamps = false;
$this->increment('view_count');
$this->save();
}
So you can call
$post->incrementViewCount();
Replied to FullCalendar Is Not Defined
The 2.2.7
version uses Jquery
https://embed.plnkr.co/plunk/wx1lC8 (see script.js how to setup with Jquery)
And some more demo, https://github.com/fullcalendar/fullcalendar/tree/v2.2.7/demos
Replied to FullCalendar Is Not Defined
Replied to How To Insert And Fetch Record Same Time Using Vue
I don't think @tarang19 want do this at the same time but more do a post and return the create record (maybe @tarang19 needs some relationschip or there are some accessors / mutators for this created item). But this is just a assumption because it is a Vue question and not a Laravel / Eloquent question.
Replied to How To Insert And Fetch Record Same Time Using Vue
Hi @tarang19
You can use axio to do a post and return some data.
This article will help you, https://www.itsolutionstuff.com/post/laravel-vue-js-axios-post-request-example-and-demoexample.html to do this.
Replied to FullCalendar Is Not Defined
Hi @afoysal
What is the js output and source from
{!! $calendar->calendar() !!}
{!! $calendar->script() !!}
?
Replied to 404, Non-objects
@hekmatyar it means there are no records in your database with status = 'published' and slug = '$slug
'
If there are records, can you show us a screenshot from those records?
Replied to 404, Non-objects
Replace
$offer = Offer::where('slug', '=', $slug)
->where('status', 'published')
->firstOrFail();
dd($offer);
with
$offer = Offer::where('slug', '=', $slug)
->where('status', 'published')
->get();
dd($offer);
To see if you have results from the query.
Replied to 404, Non-objects
Hi @hekmatyar
Are you sure you set {{ $offer->title }}
in view offers.show
?
What is the output from this dump?
$offer = Offer::where('slug', '=', $slug)
->where('status', 'published')
->firstOrFail();
dd($offer);