Coola

Coola

Member Since 3 Months Ago

Experience Points
1,480
Total
Experience

3,520 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
3
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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
1,480 XP
Oct
03
2 weeks ago
Activity icon

Replied to Laravel Google App Engine Credentials File Not Found

@laracoft it works, thanks so much was hunting for this for hours. Any idea where in the Google Cloud documentation this is mentioned just for knowledge?

Activity icon

Started a new Conversation Laravel Google App Engine Credentials File Not Found

I have a Laravel application which works fine locally. But when I deploy to Google App Engine (GAE) Standard it cannot locate the storage credentials for Google Cloud Storage (GCS).

Usually this is stored in a json file located in the credentials folder like:

GOOGLE_CLOUD_KEY_FILE="C:/laravelproject/credentials/gcs-credentials.json"

While deploying in my app.yaml I have specified it as:

env_variables:
  GOOGLE_CLOUD_KEY_FILE: "/credentials/gcs-credentials.json"

But I get an error message in the logs as:

PHP Notice: Google\Cloud\Core\Exception\GoogleException: Given keyfile path /credentials/gcs-credentials.json does not exist
 at Google\Cloud\Storage\StorageClient->configureAuthentication (/workspace/vendor/google/cloud-core/src/ClientTrait.php:133) 

I have also tried

env_variables:
  GOOGLE_CLOUD_KEY_FILE: "/tmp/credentials/gcs-credentials.json"

and

env_variables:
  GOOGLE_CLOUD_KEY_FILE: "/credentials/gcs-credentials.json"

and

env_variables:
  GOOGLE_CLOUD_KEY_FILE: "./credentials/gcs-credentials.json"

So my question is how do I specify the gcs credentials file for the GAE Standard environment in my app.yaml?

Sep
28
3 weeks ago
Activity icon

Replied to Laravel Debugbar Backtrace Not Showing

Thanks @jlrdw for the response. Yes I am hoping to get a fix for debugbar as it works well for so many other things. I will take a look at laravel telescope.

However, my original question still remains unanswered and hopefully someone else can help out.

Activity icon

Replied to Laravel Debugbar Backtrace Not Showing

Sorry @jlrdw if you do not mind could you please elaborate as I am quite new to Laravel.

Activity icon

Started a new Conversation Laravel Debugbar Backtrace Not Showing

I have laravel debugbar installed and I am trying to see which file / component is making the sql call. I have a couple of duplicate queries being run so I wanted to trace the file which was creating this duplicate query. I read that debugbar could use backtrace to see this. Backtrace option is supposed to be true by default and I checked the debugbar config in the vendor folder and that is the case.

However, when I am viewing the debugbar it is not showing the backtrace to the file. Anyone else face this issue and if so how did you resolve it? Here is a screenshot of what I see:

https://imgur.com/0zHG118

Sep
24
3 weeks ago
Activity icon

Replied to Polymorphic Many-to-many Relationship Eager Loading Producing Multiple Sql Queries

The example is just an example, not the exact situation I am facing. I cannot show you what I am building due to an NDA. If you would like I can rewrite the example but the issue still persists. The relationships are polymorphic many-to-many in my actual scenario. So please assume that they are all polymorphic many-to-many relationships - then what? Should I still expect 3 or 4 sql queries?

Activity icon

Started a new Conversation Polymorphic Many-to-many Relationship Eager Loading Producing Multiple Sql Queries

I am on Laravel 7.x and I am trying to perform eager loading on a few polymorphic many-to-many relationships for hypothetical example, a Book model as below

$details = Book::with(['author', 'publisher', 'city'])->find($id)

However laravel debugbar shows 3 sql statements for each of the relationship pivot queries. Is this normal behavior or am I missing the point of the eager loading. Shouldn't it combine it into a single query as the docs says "Sometimes you may need to eager load several different relationships in a single operation." for "Eager Loading Multiple Relationships"

Sep
18
1 month ago
Activity icon

Replied to SyncWithoutDetaching Update Timestamp On Polymorphic Many-To-Many Table

@silencebringer it feels like you have a solution to all my problems. Thanks again :)

Sep
17
1 month ago
Activity icon

Started a new Conversation SyncWithoutDetaching Update Timestamp On Polymorphic Many-To-Many Table

How can I use syncWithoutDetaching or sync to check for existing records and just update timestamp of updated_at column? I am trying to sync the data on a pivot table for a polymorphic many to many relationship. I do not want to delete any entries in the pivot table. However, I do want to update the timestamp if the entry is already there in the pivot table.

Current code:

$post->contributors()->syncWithoutDetaching($request->user()->id);
Sep
16
1 month ago
Activity icon

Replied to Validation Of Array With Required If Adjacent Field Is Filled.

Thank you both. @silencebringer your solution matches better my requirement of requiring field.*.content being required only if one of the other two are filled, else its ok if it is null.

Sep
15
1 month ago
Activity icon

Started a new Conversation Validation Of Array With Required If Adjacent Field Is Filled.

I have a form with multiple fields as


<div id="customfields">

	<div id="field0">
		<input type="text" name='field[0][name]'>
		<input type="text" name='field[0][alias]'>
		<input type="text" name='field[0][content]'>
	</div>

	<div id="field1">
		<input type="text" name='field[1][name]'>
		<input type="text" name='field[1][alias]'>
		<input type="text" name='field[1][content]'>
	</div>

	<div id="field2">
		<input type="text" name='field[2][name]'>
		<input type="text" name='field[2][alias]'>
		<input type="text" name='field[2][content]'>
	</div>
</div>

The data sent in the request. Looks like:

      "field" => array:3 [▼
        0 => array:2 [▼
          "name" => "field1 name"
	  "alias"   => ""
          "content" => "field1 content"
        ]
        1 => array:2 [▼
          "name" => "field2 name",
	  "alias"   => "field2 alias"
          "content" => "field2 content"
        ]
        2 => array:2 [▼
          "name" => ""
	  "alias"   => "field3 alias"
          "content" => "field3 content"
        ]
      ]

How can I validate that for a field either name or alias is filled and if yes the content should also be filled?

Sep
14
1 month ago
Activity icon

Replied to Create A Relationship/query Where Pivot Data Is Of Certain Value.

I liked your second method. Exactly what I was looking for.

Activity icon

Started a new Conversation Create A Relationship/query Where Pivot Data Is Of Certain Value.

I have a polymorphic many-to-many relationship between Users-Articles and Users-Tutorial. An Article/Tutorial can have multiple users as contributors but only one user can be the creator of the Article/Tutorial. I store the creator in the pivot table as boolean value in the column creator. The reason I did this was it would make it possible for me to retrieve all the contributions of a user, while minimizing redundancy.

articles
    id - integer
    name - string

tutorial
    id - integer
    name - string

users
    id - integer
    name - string
    email - string

contributables
    user_id - integer
    contributable_id - integer
    contributable_type - string
    creator - boolean

I can retrieve all articles contributed by a user using the following function in the User model:

    public function articles()
    {
        return $this->morphedByMany(Article::class, 'contributeable')->withTimestamps()->withPivot('creator');
    }

My question is how can I define a relationship in Users model or query in a Controller to retrieve any Articles where the user is the creator using the pivot column?

Sep
11
1 month ago
Activity icon

Replied to Polymorphic Many-to-Many Relationship 'where' Clause On Table After Pivot

Thanks. I was over complicating things in comparison to your solution. It works great!

Sep
10
1 month ago
Activity icon

Started a new Conversation Polymorphic Many-to-Many Relationship 'where' Clause On Table After Pivot

I have a polymorphic many-to-many relationship with posts and videos such that posts or videos are either visible if 'public' or if the user is associated to the post via the peekables pivot table.

posts
    id - integer
    name - string
    visibility - string // e.g. 'private', 'public'

videos
    id - integer
    name - string
    visibility - string // e.g. 'private', 'public'

users
    id - integer
    name - string

peekables
    user_id - integer
    peekable_id - integer
    peekable_type - string // 'App\Videos' or 'App\Posts'

How do I retrieve the all posts which are either having their visibility set to 'public' or which have a specific user_id associated via the peekables table along with pagination of '5' using Eloquent?

Sep
09
1 month ago
Activity icon

Replied to Polymorphic Many-to-many Dynamically Call Related Models For Many Types Of Tags

Thanks. Works like a charm. Is this mentioned in the documentation somewhere?

Activity icon

Started a new Conversation Polymorphic Many-to-many Dynamically Call Related Models For Many Types Of Tags

I have several types of "tags" which can be attached to a model. So I created a trait to put the tags based on the type of tag.

public function putTag($tagArray, $tagname, $modelinstance) 
{
          if ($tagname === 'tag1') {
            $modelinstance->tag1()->attach($tagArray['id']);
          }
          if ($tagname === 'tag2') {
            $modelinstance->tag2()->attach($tagArray['id']);
          }
          if ($tagname === 'tag3') {
            $modelinstance->tag3()->attach($tagArray['id']);
          }
         ...
          if ($tagname === 'tagX') {
            $modelinstance->tagX()->attach($tagArray['id']);
          }
}

is there a way to programmatically call tagX so that these if statements can be simplified into a single statement?

Sep
08
1 month ago
Activity icon

Replied to Many-to-Many Joining/pivot Table With More Fields

@expdev07 They are just terms (string fields) to be saved.

Activity icon

Started a new Conversation Many-to-Many Joining/pivot Table With More Fields

Pardon my naivety in advance. I have a table (Table A) which needs to link to another table of items (Table B) via a many-to-many relationship. However, the way in which Table A items link to Table B items can be either in "adds" or "removes" ways. In addition, Table B items can relate to Table A items in both "adds" and "removes" ways.

My questions are therefore,

  1. How do I go about designing the joining table for the many-to-many relationship? Is it just simply to put an additional column in the joining table with a column of "linking_type"?

  2. Also how would I access this data from the pivot table?

I am a little lost in the documentation sorry.

Aug
20
2 months ago
Activity icon

Started a new Conversation Laravel GCloud App Engine Standard PHP Notice: Symfony\Component\HttpKernel\Exception\NotFoundHttpException In /srv/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteColl

I thought I would share something which I noticed and I think this is the best place to post it as it is a problem and a solution. I may myself refer to this in the future but it might help others.

The issue I faced was when I deployed my Laravel project (v7) to Google App Engine (GAE) Standard (php v7.3), the website would show everything fine, but the there would be the following error which shows up in the Cloud console:

PHP Notice: Symfony\Component\HttpKernel\Exception\NotFoundHttpException in /srv/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:43

It turns out the issue was because of favicon. I added the following to my handlers in the app.yaml file to fix it:

handlers: 
- url: /favicon\.ico
  static_files: public/favicon.ico
  upload: public/favicon\.ico

If anyone sees such error maybe this will help them.

Aug
16
2 months ago
Activity icon

Replied to Laravel On Gcloud Standard

Sorry for the late response. Were you able to solve it? What was your post-install-cmd in your composer.json as that for me gave me tons of errors. I finally settled for something like:

"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"@php artisan optimize:clear", //clears all cache
"@php artisan optimize", //optimizes all caches
"composer dump-autoload",
"chmod -R 755 bootstrap\/cache",
"@php artisan cache:clear" // clears the cache
]

I had several caching issues when redeploying, so it turned out that I need to clear the caches upon deployment to app engine.

Aug
12
2 months ago
Activity icon

Replied to Laravel On Gcloud Standard

I have recently used it with Laravel 7. Are you getting a specific error? Maybe I can help (although I must say I am new to it too).

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

Thanks. I just checked it is Base64 as I copied it and put it into a base64 decoder and it shows the same thing as what is there if you use file driver system.

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

Thanks @jlrdw and @sinnbeck. I think the docs are great if not wonderful in comparison to anything I have built, so I shouldn't be complaining :). And yes its just me being curious how it works, most people would be fine with what's there in the docs. Brevity in the docs is important to lure people to using it by simplifying it I suppose and I would definitely encourage anyone to look at Laravel as a framework. @jlrdw I have marked your first answer as best answer and if anyone is interested I suppose they can just scroll down and read our conversation.

Aug
11
2 months ago
Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

Thanks @jlrdw for bearing with my questioning :). But unfortunately this part was not mentioned in the documentation. They should probably mention it I suppose?

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

I think I figured it out. Correct me if I am wrong. In the database, the data which otherwise would be stored in the file is stored under the payload column but it is encrypted in some form (I read could be base64). This adds security I suppose but it means that the data which can be stored are limited by the payload column TEXT type capacity.

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

My app runs on GCP App Engine. So I am not sure if database would be better (I am assuming it helps retain the sessions better).

When we use file as the Session Driver, and we put data into the session (as shown above) it gets saved in a file.

I just tried using the Database as the Session Driver and everything works fine without creating any extra columns. But I do not see where the data which we put into a session gets saved (or at least temporarily)?

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

No I understand that. I am wondering where the (stored data)[https://laravel.com/docs/7.x/session#storing-data] is stored in the relational database i.e. do I need to add a new column to the sessions table for the specific keys?

Activity icon

Replied to Is It Ok To Leave The Session_driver As File For Production?

Also if we use database driver, where does the extra data get saved if we use $request->session()->put('key', 'value');?

Activity icon

Started a new Conversation Is It Ok To Leave The Session_driver As File For Production?

I would like to know what are the advantages of using the database as the session driver in comparison to the file in Laravel 7 and if it is ok to use the file as the session driver.

Aug
03
2 months ago
Activity icon

Replied to Timed Sessions In Laravel 7

Anyone got any other suggestions?

Aug
01
2 months ago
Activity icon

Replied to Timed Sessions In Laravel 7

@jlrdw Thanks for the response. The solution you provided counts from the point of last activity, while I want it to be independent of that. That is the time must start from login and go on for 2 hrs say. Also the solution does not mention where I would need to add those lines of code (which file) especially since Laravel 7 uses Laravel/UI and somethings have moved around.

Activity icon

Started a new Conversation Timed Sessions In Laravel 7

Is there a way to place a timer on the user session for e.g. 2 h limit, and automatically ask the user to login again once the timer expires? This is regardless of "last activity", so the timer starts from the moment they login. Also to show a countdown clock of how many minutes left in the session?

To add: I have looked at the documentation for storing data into session, where I could possibly save the login time upon authentication. But I am not sure where to put this (and how). I could possibly then retrieve it from the session as well.

Jul
29
2 months ago
Activity icon

Replied to Laravel Use MySQL Or Firebase/NoSQL?

Thanks @martinbean. I think I will go with MySQL for the time being but maybe try Firestore in an independent project just to see if it works. I might update here on my findings if it helps others.

Jul
28
2 months ago
Activity icon

Replied to Laravel Use MySQL Or Firebase/NoSQL?

@tray2 thanks for your response. You are right it is more of a database question, but laravel and the database do go hand-in-hand. I am not just worried about performance but also maintainability and ability to expand to new data types, which is where I feel the NoSQL database would offer some advantages due to its flexibility. Thanks for the link, I will definitely check it out, I also checked out https://serversforhackers.com/laravel-perf which is a Laravel Performance course for free, so not sure how much of an overlap there is.

Jul
27
2 months ago
Activity icon

Replied to Laravel Use MySQL Or Firebase/NoSQL?

@martinbean thanks for your response. The CMS is for a laboratory so there are tables for diseases, cells, proteins, cell locations, tissues which belong to multiple types of experiments. So these tables are related to the experiments in a many-to-many relationship but the experiments themselves are of several types and hence polymorphic. Experimental data will run into 100s of thousands of rows easily and I think SQL would be great for that, but what worries me are the polymorphic relationships, e.g. there may be use cases where the scientists may need to check disease or cell data across for a specific data point on the fly. So I am not even sure if Laravel can handle manythrough queries through a many-to-many polymorphic table.

Activity icon

Replied to Laravel Use MySQL Or Firebase/NoSQL?

Such comparison sites are what confuses me, and therefore I would like to hear from anyone who actually tried both databases and what their experience was.

Jul
26
2 months ago
Activity icon

Started a new Conversation Laravel Use MySQL Or Firebase/NoSQL?

I am setting up a content management system in Laravel using Google Cloud Platform. This CMS will have quite a few polymorphic many-to-many relationships (at least 10) and for that reason I am considering whether I can use Firebase or other NoSQL databases with Laravel.

I know that there is a laravel-firebase package by Kreait which should allow me to use the firebase as database. My question is therefore

  1. Are there any drawbacks to using firebase with laravel, which I should be aware of?
  2. Can I possibly use a hybrid model where some data is stored in the SQL database while other is stored in firebase
  3. Or should I just stick to MySQL and create the several polymorphic many-to-many relationships?
Activity icon

Replied to Laravel On Google App Engine Standard Vs Flexible

This question was answered on Server Fault but the gist of it is that I settled for standard environment because of low usage as standard environment can wind down to 0 instances thereby tremendously reducing costs.

Jul
24
2 months ago
Activity icon

Started a new Conversation Laravel On Google App Engine Standard Vs Flexible

I am deploying a Laravel app (content management system) on GCP App Engine but I am not sure what are the advantages or disadvantages of standard vs flexible environment and how it would impact a Laravel application. The application will not have many users but will require to read the database and show outputs etc. Could someone please highlight differences and provide suggestions.

Jul
21
3 months ago
Activity icon

Replied to Laravel JSON File Search And Return Json As Ajax Call?

Thanks for a response. Is there a way in laravel to add the json to the database? How would I go about it? For example, I found this on the web https://vannstudios.com/how-to-insert-json-file-data-into-mysql-database-table-using-laravel do you think this is a good way to add the data from the json file to the database. The json file will be updated every few months.

Activity icon

Started a new Conversation Laravel JSON File Search And Return Json As Ajax Call?

I am new to laravel in general and I have run into an issue. I have data in a diseaseList.json file in the following format with over 5000 entries:

[{
	"name": "2,4-dienoyl-CoA reductase deficiency.",
	"id": "DI-04240",
	"acronym": "DECRD.",
	"definition": "A rare, autosomal recessive, inborn error of polyunsaturated fatty acids and lysine metabolism, resulting in mitochondrial dysfunction. Affected individuals have a severe encephalopathy with neurologic and metabolic abnormalities beginning in early infancy. Laboratory studies show increased C10:2 carnitine levels and hyperlysinemia.",
	"references": "MIM; 616034; phenotype. MedGen; CN037048. MeSH; D020167. MeSH; D028361."
}, {
	"name": "2-aminoadipic 2-oxoadipic aciduria.",
	"id": "DI-03673",
	"acronym": "AMOXAD.",
	"definition": "A metabolic disorder characterized by increased levels of 2-oxoadipate and 2-hydroxyadipate in the urine, and elevated 2-aminoadipate in the plasma. Patients can have mild to severe intellectual disability, muscular hypotonia, developmental delay, ataxia, and epilepsy. Most cases are asymptomatic.",
	"references": "MIM; 204750; phenotype. MedGen; C1859817. MeSH; D000592."
}, {
	"name": "3-alpha-hydroxyacyl-CoA dehydrogenase deficiency.",
	"id": "DI-00002",
	"acronym": "HADH deficiency.",
	"definition": "An autosomal recessive, metabolic disorder with various clinical presentations including hypoglycemia, hepatoencephalopathy, myopathy or cardiomyopathy, and in some cases sudden death.",
	"synonyms": "HAD deficiency. Hydroxyacyl-coenzyme A dehydrogenase deficiency. SCHAD deficiency.",
	"references": "MIM; 231530; phenotype. MedGen; C1291230. MeSH; D008659."
},
... (5000 more entries)
]

I would like to create an api for my application to be able to search this JSON data for the name and return it as a json so that I can populate a select field using javascript (select2js).

What is the best way to do this? Is it to create a controller to specifically open the json file, parse it, filter the results and return as a json? If yes how do I a go about the logic of the controller? Or is there some other method to do it which I am not aware of?

Also is it better to have this as a JSON file or should I save it to my database as MYSQL JSON datatype?