Member Since 1 Year Ago
4,140 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.
Started a new Conversation Laravel Cashier Single Charge For Api
Hello Everyone. I am using laravel cashier for payments. and i have implemented it on web side here is what it looks like
public function payment(Request $request)
{
$intent = auth()->user()->createSetupIntent();
return view('page.payment', compact('intent'));
}
public function submitPayment(Request $request)
{
$user = auth()->user();
$paymentMethod = $request->input('payment_method');
try {
$user->createOrGetStripeCustomer();
$user->updateDefaultPaymentMethod($paymentMethod);
$user->charge(3 * 100, $paymentMethod);
} catch (\Exception $exception) {
return back()->with('error', $exception->getMessage());
}
return redirect()->back()->with('success', 'Payment done.');
}
This thing is working fine. Now the Problem is i want to create a payment API in Laravel for mobile. And i have no idea how to do that should i send intent and they will give me Payment method or some thing else.
Also, I Just read online somewhere that you will receive few fields from api include Number, Expiry Year, Expiry Month, CVC and Name using these fields you can create a stripe Token and use that for Payment.
So i ended up like This but Not Working. Here is the Code.
public function apiSubmitPayment(Request $request)
{
$stripe = array(
"secret_key" => config('services.stripe.stripe_key')
"publishable_key" => config('services.stripe.stripe_secret')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$stripeToken = Token::create(array(
"card" => array(
"number" => $request->get('number'),
"exp_month" => $request->get('exp_month'),
"exp_year" => $request->get('exp_year'),
"cvc" => $request->get('cvc'),
"name" => $request->get('name')
)
));
$user = auth()->user();
try {
$user->createOrGetStripeCustomer();
$user->updateDefaultPaymentMethod($stripeToken);
$user->charge(3 * 100, $stripeToken);
} catch (\Exception $exception) {
return $this->response(Response::HTTP_OK, $exception->getMessage(), []);
}
return $this->response(Response::HTTP_OK, 'Data fetched Successfully', [
'advert' => new AdvertResource($advert),
]);
}
Any Help would be great full please help me out of this i really need a solution for this.
Replied to Info: Need Clearification On Mail Setting In .env File.
@imrodrigoalves thanks for your reply. but the thing is. while using mailtrap we need to add those 2 fields.
but i am sending mail from server (project is on server) to users email using these settings.
MAIL_MAILER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
and they are working fine.
Started a new Conversation Info: Need Clearification On Mail Setting In .env File.
Hello everyone. i want to know that what are these variable are for ??
MAIL_USERNAME=null
MAIL_PASSWORD=null
i just test that you can send mail to users even if these variables are null i just set MAIL_FROM_ADDRESS
in my env and it send mail corectly. then what are the above mention variables are for.
Please explain if anyone know anything about it.
Replied to Image With Laravel
by the look it look like your string quotes is creating the issue.
do something like this
"html" => '<p><img src="/tinymce/image/view?imageUrl=documents/tinymce/5d3036a15123d" alt="" width="100%" height="70" />
'Replied to How To Show Multiple Selected Data While Editing In Drop Down
@emfinanga yes please provide array of selected values in second parameter.
in_array($dt->unit_id, $data->slave_ids)
this will look like this
in_array(2, [2, 4, 8])
something like this.
Replied to How To Show Multiple Selected Data While Editing In Drop Down
i didn't understand your data properly. but if u have array of selected values in $data->slave_ids
you can try this in option
tag
<option value="{{$dt->unit_id}}" {{ in_array($dt->unit_id, $data->slave_ids) ? 'selected' : ''}}>{{$dt->Devicenumber}}
Replied to Ps Aux Exec In Schedule
is there anyone who can answer this question?
i am trying to run exec("ps aux")
command through CRON job but what i think is that we need to provide the full path like exec("usr/bin/php ps aux")
something like this we normally do for artisan command for CRON job to run it.
exec("ps aux")
command is working fine in browser but when run through CRON it didn't work.
any can tell us what we need to do to run this command through CRON. what path we need to add in the command.
Thanks.
Awarded Best Reply on How To Get Full Command Name Of Background Process.
hello @sr57 thanks your kind reply.
yes as you are showing your result i get my result like that as well. There is a process id in the start and after that there is a command.
my output is no different then yours but some how your command string is full while my command string got cut after specific length. something like this if i use your example
[83] => 465 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c conf
something like this.
But i just found the solution on stackoverflow where they told that, by default we didn't get enough buffer size that could output the full command string. so we need to do either of the thing
exec('ps -ef | grep java > /tmp/mytmpfilename.txt')
var_dump(file_get_contents('/tmp/mytmpfilename.txt'));
-w
in the command that will show the full output something like this (this is what i was looking for)exec('ps -ewwo pid,command', $processes);
exec('ps -auxww', $processes);
when i use single -w
it was not enough to show full string so i added 2 -ww
and that show the full string. though i dont need 2 -ww
just single was enough for my need
Thank you for your response
Replied to How To Get Full Command Name Of Background Process.
hello @sr57 thanks your kind reply.
yes as you are showing your result i get my result like that as well. There is a process id in the start and after that there is a command.
my output is no different then yours but some how your command string is full while my command string got cut after specific length. something like this if i use your example
[83] => 465 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c conf
something like this.
But i just found the solution on stackoverflow where they told that, by default we didn't get enough buffer size that could output the full command string. so we need to do either of the thing
exec('ps -ef | grep java > /tmp/mytmpfilename.txt')
var_dump(file_get_contents('/tmp/mytmpfilename.txt'));
-w
in the command that will show the full output something like this (this is what i was looking for)exec('ps -ewwo pid,command', $processes);
exec('ps -auxww', $processes);
when i use single -w
it was not enough to show full string so i added 2 -ww
and that show the full string. though i dont need 2 -ww
just single was enough for my need
Thank you for your response
Started a new Conversation How To Get Full Command Name Of Background Process.
Hello everyone.
OVERVIEW
I am trying to view a list of background processes of server which i am able to do using this command
exec('ps -eo pid,command', $processes);
it return an array of all processes pid and command name. this is working fine.
when i run the command above it return 2 columns pid and command, the command name contain the command name whatever it is, just for info here is basic laravel background example command.
/opt/cpanel/ea-php73/root/usr/bin/php artisan inspire
ISSUE
in this example the command name /opt/cpanel/ea-php73/root/usr/bin/php artisan inspire
is not that long. but when command name is a bit longer then this command exec('ps -eo pid,command', $processes);
trim the command name half way. due to that i am not able to search the process name using grep
WHAT I NEED
so anyone here can tell me any command that could return a full string of that command along with pid.
for your info i used these as well 'ps -aux, ps -l, ps -ef'
and few other combinations but no luck.
thank you for help.
Started a new Conversation Laravel Scheduler WithoutOverlap Issue.
Hello everyone, please i need a quick help.
i am using laravel scheduler to run my tasks. For everyone info there is no issue with cron or schedular function/commadn.
The issue is i have run command with withoutOverlap
method on schedualr. and that command some how go into memory error that is resolved. but the isseu is due to overlap method my command is in lock state.
i search online they say go to storage/framework. there u will find schedule-******* something like this but i dint have any file like that i am using laravel 8.
please i need help. i dont want my commadn to overlap so i need that functionality badly
thanks in advance. Please help
Replied to Laravel Queue Job Neither Completing Not Failing
@chaudigv also when u r here can i ask u something else.
someone in my team just run queue:work on the server now that thing is continuously running on server do u know how can i stop all queue on the server
Replied to Laravel Queue Job Neither Completing Not Failing
@chaudigv thats for your response. i already have try catch but the thing at some point code just stop. i mean just stop stop after that point it didnt work nor throw any exception.
i just try to run that code with dispatchSync() and that work fine but once it goes to queue then it didn't work there.
still trying to figuring out if i found something i will mention that here as well.
Started a new Conversation Laravel Queue Job Neither Completing Not Failing
Hello everyone.
i have a function in which i am using MailBox/Imap to read specific mails from gmail. that function was working fine no issue in that. but when i put that function in queue job and dispatch it that job appear in database jobs table and i execute that by running "queue:work --stop-when-empty" using CRON job on server.
After that in database jobs table the attempt column is change to 1 reserved_at time is set. but its almost an hour that job is neither completing nor failing.
Note: i am also dispatching other jobs and executing them through CRON they are working fine.
Started a new Conversation How To Stop (single/All) Queue Workers On Shared Hosting
Hello Everyone, i want do ask does anyone know how can i start a queue worker in shared hosting.
i have run this command on shared hosting
$schedule->command('queue:work')->everyMinute()->name('place_order')->withoutOverlapping();
now the problem is it is continuously running on the server i want to stop this queue.
Started a new Conversation Convert Recursive Array To Single Array
Hello Everyone. this is what i have as array
[
"id" => 1,
"name" => 'hello',
"another" => [
"id" => 2,
"name" => 'hello',
"another" => [
"id" => 3,
"name" => 'hello',
"another" => null
]
]
]
and i want it to be like this
[
"id" => 1,
"name" => 'hello',
]
[
"id" => 2,
"name" => 'hello',
]
[
"id" => 3,
"name" => 'hello',
]
Awarded Best Reply on Blade Directive Not Working
@sr57 @faeza97 thanks guys i found the problem.
the problem is here;
auth()->user()->isLevel(User::LEVEL_ADMIN)
if i am admin it retirn "true" if not the it return nothing as false.
Note: i also check this condition in blade and routes there its returning the correct "true", "false". and in Service provider it is also returning "false" as well but as soon as it goes to if condition it turn black don't know y
so the condition bocome something like this
<?php if () { ?>
if condition with empty brackets.
so this is what i have to do to make it work
Blade::directive('admin', function () {
$isAdmin = auth()->user()->isLevel(User::LEVEL_ADMIN) ? true : 0;
return "<?php if ($isAdmin) { ?>";
});
Blade::directive('endadmin', function () {
return "<?php } ?>";
});
Replied to Blade Directive Not Working
@sr57 @faeza97 thanks guys i found the problem.
the problem is here;
auth()->user()->isLevel(User::LEVEL_ADMIN)
if i am admin it retirn "true" if not the it return nothing as false.
Note: i also check this condition in blade and routes there its returning the correct "true", "false". and in Service provider it is also returning "false" as well but as soon as it goes to if condition it turn black don't know y
so the condition bocome something like this
<?php if () { ?>
if condition with empty brackets.
so this is what i have to do to make it work
Blade::directive('admin', function () {
$isAdmin = auth()->user()->isLevel(User::LEVEL_ADMIN) ? true : 0;
return "<?php if ($isAdmin) { ?>";
});
Blade::directive('endadmin', function () {
return "<?php } ?>";
});
Replied to Blade Directive Not Working
@faeza97 1 thing that i found is i have 2 directives @admin and @superadmin. when i login through super admin then @superadmin work fine and @ admin through error.
and when i login through admin then @admin work fine and @superadmin through the same error
do u know anyting that will be help full
Replied to Blade Directive Not Working
@faeza97 that syntex still not working it still saying "syntax error, unexpected ')' " i really appreciate your help.
Replied to Blade Directive Not Working
i also have exact same directive for other role that seems working fine but not this one
Replied to Blade Directive Not Working
Started a new Conversation Blade Directive Not Working
Hello I am trying to createa a blade directive here take a look
Blade::directive('admin', function () {
$isAdmin = auth()->user()->isLevel(User::LEVEL_ADMIN);
return "<?php if ($isAdmin) { ?>";
});
Blade::directive('endadmin', function () {
return "<?php } ?>";
});
and i use it like this
@admin()
@endadmin
but here is the error that i get
ParseError syntax error, unexpected ')' in your view....
Started a new Conversation Laravel Webpack Compile All Files In Folder Into Single File.
Hello I am trying to compile all my assets from a folder in to a snigle file like:
Compile all .scss files from resources/scss/.scss into public/asset/app.css
i am using this code
.sass('resources/sass/*.scss', 'public/assets/css')
but it says
Module not found: Error: Can't resolve 'resources\sass*.scss'
so please guide how do i do that
Replied to Laravel Image Upload Issues ( Experts Please )
@loyd here is the code
public static function StoreImage($image, $fieldName, $path)
{
$thumbData = [];
$imageData = [];
if (isset($image)) {
$fileNameWithExt = $image->getClientOriginalName();
$fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
$extension = $image->getClientOriginalExtension();
$fileNameToStore = time() . '.' . $extension;
$storagePath = storage_path('app/'.$path);
if(!File::isDirectory($storagePath)) { File::makeDirectory($storagePath, 0777, true, true); }
$imageData = self::generateImage($image, $path, $fileNameToStore);
$thumbData = self::generateThumbnail($image, $path, $fileNameToStore);
} else {
return false;
}
return $data = [
'image' => $imageData,
'thumb_image' => $thumbData,
'type' => mime_content_type($storagePath.$fileNameToStore),
'extension' => strtolower($extension),
];
}
private static function generateThumbnail($image, $path, $fileNameToStore)
{
$fileNameToStore = 'thumb_' . $fileNameToStore;
$image = self::createThumbnail($image, $path, $fileNameToStore, 200, 200);
return $data = [
'imageName' => $fileNameToStore,
'path' => $path,
'size' => $image->filesize(),
];
}
public static function createThumbnail($image, $path, $fileNameToStore, $width, $height)
{
$image = Image::make($image)->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
$image->save(storage_path('app/' . $path . $fileNameToStore)); // at this point my page goes blank
return $image;
}
private static function generateImage($image, $path, $fileNameToStore)
{
// $image = Image::make($image);
// $image->save(storage_path('app/' . $path . $fileNameToStore)); // at this point my page goes blank
$image->storeAs($path, $fileNameToStore);
return $data = [
'imageName' => $fileNameToStore,
'path' => $path,
'size' => filesize(storage_path('app/' . $path . $fileNameToStore)), // $image->filesize(),
];
}
and here is the validation for image
'nullable|image|mimes:jpeg,jpg,png|max:2048' // this is not working saying image must be an image
'nullable|mimes:jpeg,jpg,png|max:2048' // this one is working fine
Started a new Conversation Is There Laracasts Mobile (android) App??
Hi everyone. is there any mobile app for this platform ??
Started a new Conversation Laravel Image Upload Issues ( Experts Please )
Hi Everyone, i am having issues with image upload functionality. Let me just tell u that i am able to upload images to server so i am not here for enctype problem. lets just go through the point i have, and m also using laravel intervention.
saveAs
function it save my image perfectly.$image->make()
it turn my webpage to blank i mean my request stop and show a complete white page. and it happen only when i try to save image greater then 200 - 300 kB file. but intervention work fine with 20-80 kB file.'image' => 'image|mimes:jpg.etc'
it gives me error Image must be an image but when i remove "image" validation and only remain "mimes" validation then there is no error and image is saved perfectly. and again its happening with 200-300 kB file which is jpg and woking fine on 20-80 kB file which in png.anyone have any suggestions??
Replied to Laravel Telegram Api Integration
Hi, @tisuchi thank you for your quick response. i am already doing few of these things. but it didn't answer any of my question
Started a new Conversation Laravel Telegram Api Integration
Hello Laracasts, I am having an issue to get a telegram user id of a user using his/her username. Also, there are few scenarios that I want to know is that possible or not using PHP telegram api.
it will be a great help if anyone can answer the questions. Thank you.
Awarded Best Reply on Laravel Scheduler: Log File Not Working, Issue With Log.
Ok guys i found the issue. The issue has nothing to do with scheduler.
In Config directory i have a file for my domain specific variables. there i was using
<?php
return [
'app' => [
'logo' => [
'favicon' => asset('path_to_icon'),
'logo' => asset('path_to_logo'),
],
],
]
"asset()" function to set my domain logos and icons and that "asset()" was the key to this issue. don't use such functions in config file because that don't just interrupt schedulers but also no artisan command can be run.
maybe it has to do something with service containers that they don't get registered at that time that is why they throw error. maybe i don't know that for sure.
Replied to Laravel Scheduler: Log File Not Working, Issue With Log.
Ok guys i found the issue. The issue has nothing to do with scheduler.
In Config directory i have a file for my domain specific variables. there i was using
<?php
return [
'app' => [
'logo' => [
'favicon' => asset('path_to_icon'),
'logo' => asset('path_to_logo'),
],
],
]
"asset()" function to set my domain logos and icons and that "asset()" was the key to this issue. don't use such functions in config file because that don't just interrupt schedulers but also no artisan command can be run.
maybe it has to do something with service containers that they don't get registered at that time that is why they throw error. maybe i don't know that for sure.
Replied to Laravel | Check Output Before Render It To Browser
@msaied there is a blade directive @once
that make sure that the scripts is used once on a page, i hope that directive maybe helpful to you.
Here is the link to document: https://laravel.com/docs/8.x/blade#the-once-directive
Replied to Laravel Scheduler: Log File Not Working, Issue With Log.
@snapey no i configured the scheduler in cpanel that call that scheduler.
Started a new Conversation Laravel Scheduler: Log File Not Working, Issue With Log.
Hi, i am having issue with laravel scheduler.
first of all, i want to confirm that my scheduler is working fine no issue i configured my cpanel its working.
Issue
Code
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')->everyMinute();
}
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
Log::info('hello world');
Log::channel('single')->info('hello world');
})->everyMinute();
}
protected function schedule(Schedule $schedule)
{
}
** Error **
here is the error that is written to log/laravel.log file on every scheduler call
[2020-10-22 06:59:01] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined. at my_domain/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:192)
[stacktrace]
then stack trace here
[2020-10-22 06:59:01] laravel.ERROR: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in my_domain/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 65 {"exception":"[object] (TypeError(code: 0): Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in my_domain/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 65 at my_domain/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:120)
[stacktrace]
Replied to Laravel Map Request To FormRequest
@sinnbeck you are right after testing i find out it was my fault your answer is working fine.
@automica I did mark sinnbeck answer as best answer as you suggested.
but @sinnbeck i request you to add the link given below in your best answer so other people can see other perspective and know how to validate this new request.
Thanks for both of u guys.
here is the Link: https://laracasts.com/discuss/channels/code-review/is-there-a-way-to-make-a-form-request-from-another-request?page=1
Replied to Laravel Map Request To FormRequest
@sinnbeck ok i have found the answer to the problem. Here Is The Solution
$userRequest = UserRequest::createFrom($request);
this syntex only return instance of UserRequest. it didn't validate the the request it self. One must have to validate separately by using old fashion syntex like this.
$this->validate($userRequest, $userRequest->rules())
hope this may help others.
You can see the original answer Here
Replied to Laravel Map Request To FormRequest
@sinnbeck hi. as u mention in the last reply i did that but it return a simple Request Instance not UserRequest instance. or is there something that i am missing.
$userRequest = Request::createFrom($request, new UserRequest());
Replied to Laravel Map Request To FormRequest
@sinnbeck yes i could. but i want to validate the Request comming from the newStore(Request $request) plus i am also mutating and adding values in UserRequest. so is their any way i can Map the Request to UserRequest?
Replied to Laravel Map Request To FormRequest
@sinnbeck because i am using UserRequest for web, now for api i am receiving different name parameters.
what i am trying to do is to receive Request then mutate the request and pass that Request to UserRequest. so that i can use the same request for both functions.
Started a new Conversation Laravel Map Request To FormRequest
Hi i am trying to map my Request instance to FormRequest as an example here is the code.
public function store(UserRequest $request)
{
// code ...
}
now i want to call above mention store function from another function that accept only Request like this.
public function newStore(Request $request)
{
$this->store($request) // <= here is the issue that function accept FormRequest while i have only Request;
}
please help
i alsoe tried this
public function newStore(Request $request)
{
$userRequest = new UserRequest([], $request->all());
$this->store($userRequest);
}
still not working