souvikbhattacharyas

souvikbhattacharyas

Member Since 10 Months Ago

Experience Points
2,790
Total
Experience

2,210 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
20
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,790 XP
Jan
05
9 months ago
Activity icon

Replied to Singletone Not Working In Laravel

@JLRDW - Thanks. I will look for cache eloquent collection

Activity icon

Replied to Singletone Not Working In Laravel

@JLRDW - My status table is very small but for each request there would be 4-5 call to get details of multiple status.

In case of java what I would prefer that I will write a singletone class where when it initialze(Constructor) I will fetch the records and will create a hashmap. Now I can fetch it without database call.

Now to make it single tone I will make the constructor private and from a getInstance method Inwill check if the object already initialized and if yes will return the same object which hold the hashmap with value.

Now this object will remain in java memory and will be available and I will also avoid the database calling more then once.

Activity icon

Replied to Singletone Not Working In Laravel

@JLRDW - In java we can keep the class loaded in server till the server restart. So, if you keep a list with value loaded in the the object then it can be used without loading.

Now in forum I dont want to go to argue between java and php but you guys solved my issue and many thanks for the same.

My intention is to reduce the db call so I will find an alternate may be an array.

Thanks for the help.

Activity icon

Replied to Singletone Not Working In Laravel

@SNAPEY - Thats all I wanted to know. I will find an alternative solution to resolved my issue.

Thanks for you clarification.

Activity icon

Replied to Singletone Not Working In Laravel

I think u mis understand the concept or what I am trying to ask. Also it may differ technology or framework wise. But I am telling for Java.

Singletone is all about one instance of the object. This one instance does not depends on the request and response. So, in java if I load a class on start up and kept the object then whenever I will do getInstance() it will return the same object with same hascode. Now its my personal logic that I will keep data in that object or not.

But here in laravel for http request it creates a new object but within same request it keeps as a singletone.

So, my question was very simple that can I have anything like the same I used to do in java...

If this is not possible then I will go for some array or map to save my db calls.

Activity icon

Replied to Singletone Not Working In Laravel

I understand the concept but with a background of Java I am looking for singletone. In java if you create a singletone class it should remain for project life cycle. So, is there anyway to do that.

Activity icon

Replied to Singletone Not Working In Laravel

Hi, Then can you suggest me to have a process to have a singletone for project life cycle. Because I will need to load the status table for nly once and every time it should be fetched from the loaded value.

Jan
04
9 months ago
Activity icon

Replied to Singletone Not Working In Laravel

Hi, Didn't get what you are trying to mention. My problem is in every http request new singletone instance is getting created instead of a single object for project lifetime.

Jan
02
9 months ago
Activity icon

Started a new conversation Singletone Not Working In Laravel

Hi, I have a status List table and wants to load all the status on run time and kept it into the map for future use during the project lifetime. So, I have choose to use single tone structure (Don't wants to use cache for a very small record set). So, approach I have taken -

I have written a StatusDetailsUtiity class which will load the status list during the object creation.

public function __construct()
{
    // Load status during object creation.
    $this::loadStausDetails();
}

public static function getInstance()
{
    Log::debug("Single getInstance called");
    return app('T2R_Status');
}

Then load the single tone class I used AppServiceProvider - boot() method.

$this->app->singleton('T2R_Status', function ($app) { return new StatusDetailsUtiity(); });

Now the problem is on every request from browser it creates new object.

Can you tell me where is the problem.

Dec
21
9 months ago
Activity icon

Replied to Laravel Encryption Of Data

@D9705996 - Thanks for the details.

Activity icon

Replied to Laravel Encryption Of Data

@D9705996 - Thanks. But please suggest what approach is better?

  1. Encrypt the data and store it in Database. So, anyone with access to database will also not understand what stored.

  2. Or store in db as plain text and mask during the display??

Actually I heard about the EUROPEAN UNION GDPR rule and trying to be compliiance with that...

Activity icon

Replied to Laravel Encryption Of Data

@D9705996 - Thanks for the answers. Can you clarify #2 a bit.

#1 - R u referring I will add my custom value. I found in hashing.php it's already mentioned. 'bcrypt' => [ 'rounds' => env('BCRYPT_ROUNDS', 10), ],

#2 - Actually my intention is to mask the value.Like for mobile instead of showing the full number it will do XXX4XX0052. So, can you suggest me an approach that it should be done on the DB layers (MySQL) or will do it at time of returning the value with help of resource.

#3 - I will proceed with the existing solution.

Activity icon

Replied to Customize Passport Queries

I am also not planning to chnage its default behaviour. But for authentication passport already allow to extend and use custom method in your model(findForPassport()). This is required becuase database structure can be different.

Now every request Authorization is anything available. Becuase as u can see that passport only checks that the user exist in the database or not but my requirements is to check that e user exist or not along with test the user is valid or not. Because it may possible that during this session admon invalidated that user.

Current implementation I am doing is when tbe user is invalidated I am revoking all his token to stop access.

But is there any better ways?

Dec
20
9 months ago
Activity icon

Replied to Display Class And Method Name In Log (Log Formatter)

@D9705996 - Hi, Thanks for all the help. Let me know if you found any performance impact on the same.

Can you help me with the below questions also as this remain un-answered for a long period.

https://laracasts.com/discuss/channels/laravel/customize-passport-queries https://laracasts.com/discuss/channels/laravel/customize-passport-queries-and-encryption

Activity icon

Replied to Display Class And Method Name In Log (Log Formatter)

Hi, Thanks for the help. Actually it worked for me also. But I have below questions for better understanding.

a) Will it effect the performance in production as it needs to check the process every time? b) In the IntrospectionProcessor, do we have option to only display class name and method name instead of all. I have checked the code of the processor but didn't find any.

Activity icon

Replied to Display Class And Method Name In Log (Log Formatter)

Thanks for the reply. I will also look for the solution by that time it will be great if you can help me out with an example depending on your availability.

Activity icon

Replied to Display Class And Method Name In Log (Log Formatter)

I have already gone though the tutorial you shared earlier but not been able to figure out the way I can make this happen. May be because I am new in php related technologies. Can you provide me a sample configuration.

My Requirement - Daily rotating log files stored in specified location. Class and method name should be included in the log file .

My current configuration is -

 'stack' => [
        'driver' => 'stack',
        'channels' => ['daily'],
    ],

    'single' => [
        'driver' => 'single',
        'path' => storage_path('logs/laravel.log'),
        'level' => 'debug',
    ],

    'daily' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel.log'),
        'level' => 'debug',
        'days' => 14,
    ],

.............

Any help would be appreciable.

Activity icon

Replied to Display Class And Method Name In Log (Log Formatter)

In this solution I have to write the class and function name in every log message I write. But what I want that I will put it in some centralize file and this the rest process will execute automatically. Just like in java you mention the 'Log Format' in log4j.props and everything else taken care.

Dec
19
9 months ago
Activity icon

Started a new conversation Display Class And Method Name In Log (Log Formatter)

Hi, Currently as per my monolog implementation in laravel I can see the printed message in the file which I have written with Log::debug/info. But for better control and debugging I would like to include the class name and method name on each message.

For java it can be done with formatted but how we can do it in laravel?? Any help would be appreciated.

Dec
10
10 months ago
Activity icon

Started a new conversation Customize Passport Queries

For every request I found that 4 queries are fired to validate the user and the token. Among them one is to fetch the user (select * from user) based on the user id. This queries are fired by Passport/Laravel But what I want is to modify this query to add one status field check also to check if any user become invalid during the token validity period. If we only check with the id then if any user become inactive(By changing status then also we will not be able to stop the user as deleting the token for the user is not a good solution for me).

Queries Fired on every request by Passport Laravel:

select * from oauth_access_tokens where id = ? select * from user where id = ? limit 1 ["2"] select * from oauth_access_tokens where id = ? select * from oauth_clients where id = ?

So, can anyone tell me how to change the 'select * from user where id' query in passport at time of Token validation.

Dec
07
10 months ago
Activity icon

Started a new conversation Laravel Encryption Of Data

Hi,

For my current project I have already implemented Passport with Laravel. But during the authentication & authorization I have few questions which were given below.

  1. Every password in laravel is encrypted with bcrypt by default. Now I wan to customize the bcrypt implementation generally and wants to specify the number of rounds of hasing will be available. ALso I would like to do it globaly to avaoid change in password store and fetch. So, is there any way you can suggest or you views.

  2. I want to mask the user address /phone number /email in the database to avoid security breach. So, this can be accessed from the portal only. So, can any one help me to do it globally or model wise.

  3. By default url to get oauth token is '/oauth/token' but is there any way to change or add prefix on it. This is not a important part but good to have.

Please help me out.

Dec
06
10 months ago
Activity icon

Replied to Disable Updated_at Time Of Insert

I think this is a good option to handle the situation. But I am open for suggestions.

Activity icon

Replied to Disable Updated_at Time Of Insert

Then it's goes to same problem. Everywhere I have to manually add created_at and updated_at.

Is there any generic solutions to handle that if insert only created_at and for update_ updated_at will be fired.

Activity icon

Replied to Disable Updated_at Time Of Insert

@SNAPEY - I have both created_at and updated_at. Now when I need to insert record then there is no need to use the updated_at field. updated_at field will only be used at time of 'UPDATE' operation.

This will also help me to back track the transaction.

Activity icon

Replied to Disable Updated_at Time Of Insert

@SNAPEY - Is there any generic solution? Else I have to do it for every insert I have.

Activity icon

Started a new conversation Disable Updated_at Time Of Insert

Hi,

In Eloquent model I found created_at and updated_at fields are handled automatically. But updated_at field should be populated at time of Update only but I found that updated_at field also getting populated during insert.

Now I do not want to disable $timestamps = false but only wants to have control over it where created_at field will be populated during INSERT operation and updated_at fields will be populated at time of UPDATE operation.

Dec
05
10 months ago
Activity icon

Replied to Is This Good Approach To Have Own Service Provider?

Yes. Only status code will be sent.

Activity icon

Replied to Is This Good Approach To Have Own Service Provider?

Just one more question. I would like to send back ONLY status codes back from the controller with hep of response function. But in current function argument of we need to provide message and status code. So, is there any way to send only the status code with response() function.

response("Password changed successfully", 204);

One option is use $response->setStatusCode(204) but for this we need to declare the response variable which I am trying to avoid.

So, can you suggest me a good alternatives if any.

Activity icon

Replied to Is This Good Approach To Have Own Service Provider?

That means for any specific service like social media handling / messages handling I will create new services but for normal passport routing it's not needed.

But it's solely on the Architect.

Is my understanding right?

Activity icon

Started a new conversation Is This Good Approach To Have Own Service Provider?

Hi, In Laravel we already have the required service providers like AppServiceProvider Application related or AuthServiceProvider - Authentication related in my case Passport .

But is it a good approach that instead of changing in this core service providers, we write our own ServiceProvider (Project specific) and then write the Passport or other application project related configuration n the custom service provider.

Please suggest

Dec
03
10 months ago
Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

Thanks for the reply and it's working. I will ping you in anything more stuck during this implementation. But I think as of now all questions are resolved.

Earlier I tried this but not sure why it didn't work or may be some syntax issue but now it's returning expected result.

Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

I have already gone through and used resources earlier. May be I am not able to clarify my question and sorry for that. Let me re try.

Currently when I am doing auth()->user() and it's fetching all the records along with it's relationship with help of eager loading as suggested by you.

Now I would like to structure them in resource but how I will populate the records in resource.

Example:

Imagine the below relationship User Cred.php -> UserDetails.php->Accss.php->Menu.php

Now if I only like to fetch the record of UserDetails.php then I can write cred.php ->userdetails

but if I have to fetch record from Accss.php or only the record of Menu.php (To pass in a method) what will be the syntax

Like:

auth()->user()->userDetails -- it's working

auth()->user()->userDetails()->agent -- It's not working

userCredentialModel -

public function userDetails() { return $this->hasOne('App\Models\UserDetailsModel', 'user_id', 'user_id'); }

UserDetailsModel :

public function agent(){ return $this->hasOne('App\Models\AgentDetailsModel','alias_name','ta_alias_name'); }

Like t acess the agent() method and then what should be the process.

auth()->user()??

Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

@VAJID - Mine one is fully REST API dependent. So, I think this will be required. So,Currently with json(auth()->user()) I am getting the full record but it's not structured. So, how should I access the records in Resource class and popuate?

Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

Ok. Actually my plan is to use the 'Resource' of Laravel to format and return it to user as a Json response.

Currently with json(auth()->user()) I am getting the full record but it's not structured. So, how should I access the records in Resource class and popuate?

Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

Hi, Seems like it's working as expected. One more question. This is loading the things eagerly but in any case if I like to have lazy loading of accesscontrol then what would be the syntax to fetch it?

Activity icon

Replied to Retrieve All The Parent Value With Laravel Eloquent

Hi,

Didn't get the answer. I want to get the user details. Now when User details object will return I also want to load and print the accessControl list of UserDetails Model. UserCred.php public function userDetails(){ return $this->hasOne('App\Models\UserDetailsModel','user_id','user_id'); }

UserDetailsModel.php

public function accessControl(){ return $this->hasOne('App\Models\UserAccessControlModel','alias_name','ta_alias_name'); }

Please help.

Dec
02
10 months ago
Activity icon

Started a new conversation Retrieve All The Parent Value With Laravel Eloquent

After user login I would like to fetch all the details of the user logged in from it's multiple parent table like user details, it's parent details, allowed access control etc.

Relation ship is like

-> User Credential table -> User Details -> Company Details. -> User Details -> Access Control List (Mapping) -> Menu Master -> User Details -> Notification Details (Mapping)-> Notification Master

Now from user credential model I have pointed with hasOne relation ship with user details model.

In User Details model I have method to access company table,Menu mapping table and Notification Mapping table.

Now what I want that when I fetch the user details all the parent records (upto any level will be loaded and returned to me) like eager loading.

Need help the process to do the same.

Note: I have already been able to fetch the records from user details table with mapping from logged in user.

Nov
23
10 months ago
Activity icon

Replied to Service Layer In Laravel 5.7

@D9705996 - Thanks for the reply. What I understand that under app I need to have service folder to store the plain php classes and from controller I will re-direct my execution to the layer. Then service layer will do the data insert process etc.

Is my understanding right?

Nov
22
10 months ago
Activity icon

Started a new conversation Service Layer In Laravel 5.7

I have gone though the Laravel and found that every request gone though middle layer -> Controller layer ->Resource Layer. But for my project I have huge business processing logics which needs to be written. So, I am looking for a service layer option where execution control will be passed from Controller and then service layer will do the processing logic along with databae fetch. But though artisian I didn't find any service layer part. So, can you siggest me how I can manage this service layer in my project.

Nov
14
11 months ago
Activity icon

Replied to Process To Secure My REST API With Laravel

@PRIMORDIAL - Hey I have implemented the OAUTH with grant option and it's working as expected. Just one more question out of context of oauth. In normal project we have middle ware to validate all request (As per configuration), Controller to handle all the request and Model to connect with database. But how I can manage the service layer where I will right my business logic like what processing needed before sending the data. Is laravel have any option to support the same.

Activity icon

Replied to Process To Secure My REST API With Laravel

I am trying passport only. In passport we have the options mentioned above in #1 & 2. Also I dont want maintain a new server rather would like to do it in single apache. So, if u can share a link or reference to configure the same then that will be helpful.

Activity icon

Started a new conversation Process To Secure My REST API With Laravel

I am in process to design an application for a customer where the User Interface will be in Angular 6 and the back-end will be in the API.Now as I am using angular (SPA) I communicate with server though JSON and REST API. Now need your suggestions on the process to secure my API.

My Analysis -

  1. Personal Access Token is not a good idea as the tokens are always long lived. I have already done a demo on the same.

  2. Consuming Your API With JavaScript is may be a good option but it used cookies and it will be good approach or not I am not sure.

I am open for any good suggestions including other approach like JWT also if it's proves logical.

Thans in Advance.