Member Since 1 Month Ago
3,590 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 Jquery Foreach Loop With Two Array
Sorry , I have problem with website and when I post replys it not showing for me.
Started a new Conversation Problem On Laracasts.com
Hello I can not see "My Questions" on site profile anyone have same problem ?
Replied to Jquery Foreach Loop With Two Array
Hi
if(selectedVal == "' + valueA + '") {
I want check which value is set from array ListA
for set ex. Tom if(selectedVal == "Tom") {
Then $.each(valueB, function(index, value) {
create option list using array ListB
$.each(TomList, function(index, value) {
set TomList which load data from array TomList
Replied to Jquery Foreach Loop With Two Array
if(selectedVal == "' + valueA + '") {
I want check which value is set from array ListA
for set ex. Tom if(selectedVal == "Tom") {
Then $.each(valueB, function(index, value) {
create option list using array ListB
$.each(TomList, function(index, value) {
set TomList which load data from array TomList
Replied to Jquery Foreach Loop With Two Array
I have two select, In select 1 have Tom and Bob, and populating select 2 .
For ex. if select Tom create slecte 2 with options
if(selectedVal == "' + valueA + '") {
There we need but Tom
and this $.each(valueB, function(index, value) {
creates option list for tom using array TomList
Started a new Conversation Jquery Foreach Loop With Two Array
Hello , How can I loop two array in one foreach loop
//List for select
TomList = ["A","B"],
BobList = ["C", "D"],
//
ListA = ["Tom","Bob"],
ListB = ["TomList","BobList"],
///////////////
// ////// I try these two loops, but I think this is wrong
/////////
$.each(ListA, function(indexA, valueA) {
$.each(ListB, function(indexB, valueB) {
if(selectedVal == "' + valueA + '") {
$.each(valueB, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
});
});
}
it must loop like
if(selectedVal == "Tom") {
$.each(TomList, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
if(selectedVal == "Bob") {
$.each(BobList, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
Replied to JQuery For Loop
Use Like this, but not works
<script type='text/javascript'>
jQuery(document).ready(function($) {
var i;
var sumVisitors = [];
for (i = 1; i < 12; i++) {
var sumVisitors[i] = 0;
$('.total_visitors_' + i).each(function() {
sumVisitors[i] += parseFloat($(this).text());
});
$('.total_' + i).text(sumVisitors[i]);
}
});
</script>
Replied to JQuery For Loop
It will not work, I need loop like : (from 1 to 12)
var sumVisitors1 = 0;
$('.total_visitors_1').each(function()
{ sumVisitors1 += parseFloat($(this).text()); });
$('.total_1').text(sumVisitors1);
var sumVisitors2 = 0;
$('.total_visitors_2').each(function()
{ sumVisitors2 += parseFloat($(this).text()); });
$('.total_2').text(sumVisitors2);
var sumVisitors3 = 0;
$('.total_visitors_3').each(function()
{ sumVisitors3 += parseFloat($(this).text()); });
$('.total_3').text(sumVisitors3);
....
Started a new Conversation JQuery For Loop
Hi
Trying make loop , but think I am using in loop i
incorrect format
jQuery(document).ready(function($) {
var i;
for (i = 1; i < 12; i++) {
var sumVisitors+i = 0;
$('.total_visitors_'+ i).each(function()
{ sumVisitors+i += parseFloat($(this).text()); });
$('.total_'+ i).text(sumVisitors+i);
}
});
This is for ex. where is 1 want put var i
var sumVisitors1 = 0;
$('.total_visitors_1').each(function()
{ sumVisitors1 += parseFloat($(this).text()); });
$('.total_1').text(sumVisitors1);
Replied to Localization In Laravel
If you can help, how set prefix in my route , it will be better. thanks
Started a new Conversation Localization In Laravel
Hi
Using this tutorila https://salfade.com/tutorials/set-locale-from-route creating Localization
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\App;
class SetLocale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$locale = 'en'; // set en as the fallback locale
if ($request->is('/es/*')) { // if the route starts with /es/* set locale to ES
$locale = 'es';
} else if ($request->is('/fr/*')) { // if the route starts with /fr/* set locale to FR
$locale = 'fr';
}
//set the derived locale
App::setLocale($locale);
return $next($request);
}
}
protected $routeMiddleware = [
.....
'locale' => \App\Http\Middleware\SetLocale::class,
];
last step add prefix
Route::group(['prefix' => '/{locale}', 'middleware' => 'locale'], function ($locale) {
});
but my rout look like that
Route::middleware(['auth', 'roles:Administrator,Editor' , 'locale'])->group(function(){
Route::get('/admin/posts', [App\Http\Controllers\PostController::class, 'index'])->name('post.index');
});
how set prefix in my route ?
Replied to Simple User Roles Middleware
Hi Getting error : Invalid argument supplied for foreach()
p.s. what is difference using .. dot
public function handle(Request $request, Closure $next, $roles)
vs
public function handle(Request $request, Closure $next, ...$roles)
Started a new Conversation Simple User Roles Middleware
Hello Trying create Simple user roles middleware
in Role model
protected $table = 'roles';
public function users()
{
return $this->hasMany(User::class);
}
in User Model
public function role()
{
return $this->belongsTo(Role::class);
}
User DB I have role_id
And Role DB looks like:
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description');
$table->timestamps();
});
Using Middleware CheckRole
Kernel.php
'roles' => \App\Http\Middleware\CheckRole::class,
Middleware CheckRole
public function handle(Request $request, Closure $next, $roles)
{
if(auth()->check() && $request->user()->role->name == $roles)
{
return $next($request);
}
return redirect()->route('login');
}
route
Route::middleware(['auth', 'roles:Administrator'])->group(function(){
Route::get('/admin/posts', [App\Http\Controllers\PostController::class, 'index'])->name('post.index');
});
Using this code, restriction works, user must have Administrator role to access route.
But I have 2 questions
Q1.
I want use several roles
Route::middleware(['auth', 'roles:Administrator,Editor'])
in Middleware CheckRole add check for array but something not working
public function handle(Request $request, Closure $next, $roles)
{
if(is_array($roles)){
foreach($roles as $role){
if($request->user()->role->name == $role) {
return $next($request);
}
}
}
if(auth()->check() && $request->user()->role->name == $roles)
{
return $next($request);
}
return redirect()->route('login');
}
Q2.
is anything I need add in middleware for more security ?
Replied to Laravel Get Id Before Store
I think it must be $post->id
$post = Post::insert([
'title'=> $title,
'category'=> $category,
]);
Photo::insert([
'post_id'=> $post->id,
'photo'=> $photo,
]);
Started a new Conversation Laravel Get Id Before Store
Hi
in store I have post and photo
it possible store post id to 'post_id'=>
when Post::insert creates unique id for post save it to post_id
public function store(Request $request)
{
Post::insert([
'title'=> $title,
'category'=> $category,
]);
Photo::insert([
'post_id'=>
'photo'=> $photo,
]);
Replied to Laravel Validate Attach Image Number
Why image.*.*
? -I use this
<input type="file" id="image" name="image[1][]" class="form-control" multiple>
<input type="file" id="image" name="image[2][]" class="form-control" multiple>
find solution
'image.*' => 'max:30',
'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048',
Started a new Conversation Laravel Validate Attach Image Number
How check validate attach image number ?
$request->validate([
'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048',
]);
Replied to Upload Multiple Images With Multidimensional Array
It is not correct use ($image = $request->file('image'); ) this also works
$image = $request->file('image');
foreach ($image AS $category => $images) {
foreach ($images as $multi_img) {
$name_gen = hexdec(uniqid()).'.'.$multi_img->getClientOriginalExtension();
Image::make($multi_img)->resize(300,300)->save($path.$name_gen);
$last_img = $path.$name_gen;
Gallery::insert([
'image'=> $last_img,
'category' => $category
]);
}
}
or it must be like you show
foreach ($request->input('image') AS $category => $image) {
Replied to Upload Multiple Images With Multidimensional Array
After testing find problem 1. This validation not works, how can it work for multiply image?
'image.*' => 'mimes:jpeg,jpg,png,gif|max:2048'
I change with this, correct ?
'image.*.*' => 'mimes:jpeg,jpg,png,gif|max:2048'
if i use this check, upload not works
if($request->hasfile('image')) {
Replied to Upload Multiple Images With Multidimensional Array
Hello This is full code in my function , but getting error "The image.1 must be a file of type: jpeg, jpg, png, gif."
$request->validate([
'image' => 'required',
'image.*' => 'mimes:jpeg,jpg,png,gif|max:2048'
]);
$image = $request->file('image');
$path = "upload/";
if($request->hasfile('image')) {
foreach ($image AS $category => $images) {
foreach ($images as $multi_img) {
$name_gen = hexdec(uniqid()).'.'.$multi_img->getClientOriginalExtension();
Image::make($multi_img)->resize(300,300)->save($path.$name_gen);
$last_img = $path.$name_gen;
Gallery::insert([
'image'=> $last_img,
'category' => $category
]);
}
}
}
Started a new Conversation Upload Multiple Images With Multidimensional Array
Hello
Tying create Upload Multiple Images with multidimensional array
DB
Schema::create('galleries', function (Blueprint $table) {
$table->id();
$table->string('category')->nullable();
$table->string('image')->nullable();
$table->timestamps();
});
<input type="file" id="image" name="image[]" class="form-control" multiple>
controller
$path = "upload/";
foreach ($image as $multi_img) {
$name_gen = hexdec(uniqid()).'.'.$multi_img->getClientOriginalExtension();
Image::make($multi_img)->resize(300,300)->save($path.$name_gen);
$last_img = $path.$name_gen;
Gallery::insert([
'image'=> $last_img,
]);
}
This works and it uploads image.
But I want make like
<input type="file" id="image" name="image[1][]" class="form-control" multiple>
<input type="file" id="image" name="image[2][]" class="form-control" multiple>
<input type="file" id="image" name="image[3][]" class="form-control" multiple>
How make for each for this image[X][]
If file uploaded from image[1][] in 'category'=> 1
$path = "upload/";
foreach ($image as $multi_img) {
$name_gen = hexdec(uniqid()).'.'.$multi_img->getClientOriginalExtension();
Image::make($multi_img)->resize(300,300)->save($path.$name_gen);
$last_img = $path.$name_gen;
Gallery::insert([
'image'=> $last_img,
'category'=> ???,
]);
}
Replied to How Add Transition Animation To RemoveClass ?
It not works
I have like this
<button id="my-button"></button>
<div class="div-box div-hide"> text</div>
Started a new Conversation JQuery Loop And Call Array
Hello In var list have Locations data. Want send this data in differ addresses array. Formatting json in other format like {infobox_content":"test", "latitude":"1","longitude":"2"}, and saving in listNew
<script type='text/javascript'>
jQuery(document).ready(function($) {
var list = {
Locations: [
{ "id": "1", "region": "USA1", "city": "NY1", "latitude": "12.871449", "longitude": "14.588341" },
{ "id": "2", "region": "USA2", "city": "NY2", "latitude": "12.871449", "longitude": "14.588341" },
{ "id": "3", "region": "USA3", "city": "NY3", "latitude": "12.871449", "longitude": "14.588341" }
]
};
// formatting json in other json format
var listNew = $.each(list.Locations, function(i, item) {
var item = '{infobox_content":"'+item.region+'<br/>'+item.city+'", "latitude":"'+item.latitude+'","longitude":"'+item.longitude+'"},';
});
console.log(listNew)
});
</script>
Now I want put this new format json data in addresses: [] How can I do this ?
<script type="text/javascript">
var map_fusion_map_5;
var markers = [];
var counter = 0;
function fusion_run_map_fusion_map_5() {
jQuery('#fusion_map_5').fusion_maps({
addresses: [
/// {infobox_content":"test", "latitude":"1","longitude":"2"},
],
animations: false,
infobox_background_color: '',
infobox_styling: 'default',
infobox_text_color: '',
map_style: 'custom',
map_type: 'roadmap',
marker_icon: '',
overlay_color: '',
overlay_color_hsl: {"hue":0,"sat":0,"lum":100},
pan_control: true,
show_address: false,
scale_control: true,
scrollwheel: true,
zoom: 7,
zoom_control: true,
});
}
google.maps.event.addDomListener(window, 'load', fusion_run_map_fusion_map_5);
</script>
<div id="fusion_map_5" style="height:350px;width:100%;"></div>
Replied to Laravel Validating Sometimes
My goal is use two kind of validating one when required one when not required, but both of must use validating rule
=> 'required|string|min:2|max:255', // When required + validating rule
=> 'sometimes|nullable|string|min:2|max:255', // When not required + validating rule
I think this will be correct
Started a new Conversation Laravel Validating Sometimes
Hello
Making validation in larval. is this correct:
This means user must fill value, value is required
'phone_a' => 'required|string|string|min:2|max:255',
This means user can not fill value but if fill it will check validation
'phone_b' => 'sometimes|nullable|string|min:2|max:255',
This will make value required ?
'phone_c' => 'string|min:2|max:255',
Started a new Conversation How Add Transition Animation To RemoveClass ?
Hi, using jQuery, on lick button adding div-box div-hide. It work like show hide
How add Transition Animation when adding and removing class ?
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#my-button").click(function(e){
if ( $(".div-box").hasClass('div-hide') ) {
$(".div-box").removeClass('div-hide');
} else {
$(".div-box").addClass('div-hide');
}
});
});
</script>
Replied to How Disable Registration In Laravel/breeze ?
Hi
In which file is this routes? in web.php there is not such routes
Started a new Conversation How Disable Registration In Laravel/breeze ?
Hi, Using breeze for laravel
composer require laravel/breeze --dev
php artisan breeze:install
how can disable access on registration route and do not allow anyone make registration ?
Awarded Best Reply on Tempus Dominus Bootstrap 4 Set DefaultDate
Find solution
<script type="text/javascript">
$(function () {
$('#load_date').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
defaultDate: moment().format(),
});
});
</script>
Replied to Tempus Dominus Bootstrap 4 Set DefaultDate
Find solution
<script type="text/javascript">
$(function () {
$('#load_date').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
defaultDate: moment().format(),
});
});
</script>
Started a new Conversation Tempus Dominus Bootstrap 4 Set DefaultDate
Hello Using https://getdatepicker.com/5-4/
<div class="form-group">
<label for="load_date">Load Date</label>
<input type="text" id="load_date" name="load_date" class="form-control datetimepicker-input" data-toggle="datetimepicker" data-target="#load_date"/>
</div>
<script type="text/javascript">
$(function () {
$('#load_date').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
defaultDate: new Date(),
});
});
</script>
tying set default Date cornet date using defaultDate: new Date(), but it gives input by default blank
Replied to Laravel Value Validate, Get Value Name
Find problem configuration app.php
'locale' => 'en', 'fallback_locale' => 'en',
I changed this to other languages which language file missing
Started a new Conversation Laravel Value Validate, Get Value Name
Hi In my controller I have store function with validation
$request->validate([
'name' => 'required|string|max:55',
'email' => 'required|string|email|max:255|unique:users',
'personal_number' => 'required|string|min:11|max:11|unique:users',
'password' => 'required|string|confirmed|min:8',
]);
In blade displaying error
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
For ex. when enter name max 55 it gives error validation.max.string
but before I get error like (showing also value name) name max.string
Now it give error like this format validation.x.x and I can not get value name
what can be reason ?
Started a new Conversation Retrieve Data From JSON File Using JQuery And Ajax
Hi
Ajax gives data and in console log it look like: {priceType: [{pricea: 50, priceb: 20}]}
$('#list').on('change', function(){
var list = $("#list").val();
if(list != "") {
$.ajax({
url: "{{ url('/type/price/') }}/"+list,
type:"POST",
dataType:"json",
success:function(data) {
if(data){
$("#type_price_a").val(priceType.pricea);
$("#type_price_b").val(priceType.priceb);
}
},
});
}
});
I want put it in value, but i can not get data using priceType.pricea and priceType.priceb
Replied to JQuery Reset Selected Option
Hi, yes remove() deletes options but when using ajax think that value is not empty
Started a new Conversation JQuery Reset Selected Option
Hi
<select id="a_id">
<option selected="selected" value="">Choose</option>
<option value="list1">list1</option>
<option value="list2">list2</option>
<option value="list3">list3</option>
</select>
<select id="b_id">
<option selected="selected" value="">Choose</option>
<option value="list22">list2-1</option>
<option value="list222">list2-2</option>
<option value="list2222">list2-3</option>
</select>
<select id="c_id">
<option selected="selected" value="">Choose</option>
<option value="list33">list3-1</option>
<option value="list333">list3-2</option>
<option value="list333">list3-3</option>
</select>
Using 3 selected, for ex. I select A then select B and C. But when change select A reset select B and C
I did like this
$('#a_id').on('change', function(){
$('#b_id').children('option').remove();
$('#c_id').children('option').remove();
});
there is any other way make reset
Started a new Conversation Laravel Dependent Dropdown Check
Hi
Have dependent dropdown which return data.
ajax have three values and when all of them is set it gives result.
But I need add check, when a, b , c all this value is set send ajax request , now it send if one of them is set.
I need do this check, in jQuery on in controller.
In controller I try check with $a_id != null && $b_id != null && $c_id != null but this not works. In jQuery I use if(c_id) , but this always give true, also when nothing selected and by default it have Choose
<select id="a_id">
<option selected="selected" value="">Choose</option>
<option value="list1">list1</option>
<option value="list2">list2</option>
<option value="list3">list3</option>
</select>
<select id="b_id">
<option selected="selected" value="">Choose</option>
<option value="list22">list2-1</option>
<option value="list222">list2-2</option>
<option value="list2222">list2-3</option>
</select>
<select id="c_id">
<option selected="selected" value="">Choose</option>
<option value="list33">list3-1</option>
<option value="list333">list3-2</option>
<option value="list333">list3-3</option>
</select>
$('#a, #b, #c').on('change', function(){
var a_id = $("#a_id").val();
var b_id = $("#b_id").val();
var c_id = $("#c_id").val();
if(c_id) {
$.ajax({
url: "{{ url('/get/') }}/"+a_id+"/"+b_id+"/"+c_id,
type:"POST",
dataType:"json",
success:function(data) {
if(data){
$("#p").empty();
///
console.log(data);
}else{ $("#p").empty();}
},
});
} else {$("#p").empty();}
});
Controller
public function getData($a_id = null, $b_id = null, $c_id = null)
{
$a = Aaa::findOrFail($a_id);
$b = Bbb::findOrFail($b_id);
$c = Ccc::findOrFail($c_id);
return response()->json(['a' => $a, 'b' => $b, 'c' => $c]);
}
Started a new Conversation Laravel Get Json Response Using Ajax
Hello
Sending ajax request which give total price.
In controller (this works in $total gives number value)
public function getCalculate($a_id,$b_id)
{
$priceA = PriceA::select('price')->where('id',$a_id)->first(['price'])->price;
$priceB = PriceB::select('price')->where('id',$b_id)->first(['price'])->price;
$total = $priceA + $priceB;
return response()->json($total);
}
blade file using this ajax , but can not get data
$('#selectbox').on('change', function(){
if(b_id) {
$.ajax({
url: "{{ url('/get/calculate/') }}/"+a_id+"/"+b_id,
type:"POST",
dataType:"json",
success:function(data) {
if(data){
$("#totalPrice").empty();
$("#totalPrice").append(value.price); // how get data here ?
console.log(data);
}else{ $("#totalPrice").empty();}
},
});
} else {$("#totalPrice").empty();}
});
Replied to Get Json Values
I have data like this, each post have page id. and i want show only post which id is equal specific page id
[ [ //pages {"id":1,"name":"aaa"}, {"id":2,"name":"bbb"}, {"id":3,"name":"ccc"}, ],
[ //posts {"id":4,"idpage":1,"name":"aaa"}, {"id":45,"idpage":1,"name":"aaa"}, {"id":24,"idpage":2,"name":"aaa"}, ] ]