gustav1105

gustav1105

Member Since 2 Years Ago

Pretoria

Experience Points 12,630
Experience Level 3

2,370 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 44
Lessons
Completed
Best Reply Awards 7
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

28 May
2 years ago

gustav1105 left a reply on Date Accessor: Model Date To Human Carbon Date

THANKS! Exaclty what I needed

26 May
2 years ago

gustav1105 started a new conversation How To Return Data As Key Value Pair

How would I return data in a table to a key value pair.

if this is the data

id  Reference_num 
1   PP-637463276
2   P24-7376373
3   AI2373663

lets call the model Reference

Now how would I go about returning for instance

$ref = Reference::find(1);

as a key value pair where the id is the key and the reference number is the value.

gustav1105 left a reply on Laravel-mix Worked Once, Now Emits No Files.

change the assets to mix

gustav1105 started a new conversation Retrieving Aggregated Results From Many Eloquent Models For Api Request

My question concerns the output that is returned from a query. Lets say that I am querying four different tables in one api request and I send through the user id as a wildcard.

So putting the query into words, it sounds like this.

I get the user id and and find the user, then using the relationship from user to property I get the properties where the user is the owner with references and for each reference query a advertiser table to obtain the specific advertiser.

then return.

So the problem is a am getting a bit of a mess returned! All the relevant information is available, but I get all the timestamps and other information that is not particularly import to this specific request. The return lets call it output, is an object and this objects is quite bloated, where there seems to be nested objects inside nested objects (which is to be expected) but some of the nested objects seems to be only a holder for a nested object that has its own nested objects.

So not to get to off-track here, I would like to know,

What procedures, or method or methodology or tutorial will be a wise choice when working with data like this, for instance how to serialize or transform?

In a perfect world I would to return for this specific query key value pairs where the key is the id and the value is the reference (for example).

So please to all the guys that has been working with api's and have good practical ideas on how I might chronologically work through the problem please advise?

Thanks.

25 May
2 years ago

gustav1105 left a reply on How To Secure API Endpoints For An App That Doesn't Have A Login?

@derrickrozay Yes, I imagine that would be the easies, so you don't have to code in authentication just set it on your server to allow ip's

But I have just read the thread from @bashy he does make a very valid point, I haven't dug this deep into passport so can't really be opinionated but I imagine you could set the bearer token on the request... That will generate the token you need, but as the execution thereof ask @bashy.

24 May
2 years ago

gustav1105 left a reply on How To Secure API Endpoints For An App That Doesn't Have A Login?

@derrickrozay Yes I think you are right, to consume your api with passport you will have to be auth already to create a fresh api token,

Well just an idea but if the whole operation is just being done in-house, just setup your server to allow certain ip addresses through

22 May
2 years ago

gustav1105 left a reply on How To Define These Relationships In My Models.

@marthz, I understand that in some cases I would not need a pivot table, but for the project I am working on it is best to have the advertisers on their own because I use them independently in other situations not shown here, If I had not the pivot table I would not have only the advertisers to my displosal, so what I have done is to give reference a hasOne relationship to Advertiser using AdvertiserReference

and Advertiser hasMany reference using AdvertiserReference,

I havent tested yet, but according to the docs laravel 5.4 it should work

21 May
2 years ago

gustav1105 started a new conversation How To Define These Relationships In My Models.

U have three models

Advertiser
Reference
AdvertiserReference

How would I setup the relationships between these models, for the tables

advertisers 
references
advertiser_references //this is a pivot table

It goes a something like this.

There are 5 advertisers in the advertisers table and there are

1000 references in the references table.

In the advertiser_references tabel it should be thus that

each reference is connected to an advertiser, and a reference can only have one advertiser.

something like this

advertiser one -> 1234
advertiser two ->1235
advertiser three ->1236
advertiser two -> 1237
advertiser one -> 1289

Looking at elqouent with the three models how would I define these relationships on my three models.

Thanks.

20 May
2 years ago

gustav1105 left a reply on How To?

@martinbean, thanks for the advice I have done exactly like you said in my cotrollers, I have now three different controllers each keeping to its own responsibility and to keep them clean I use method injection to a "service" ( I don;t know it is the right word) but alas! So the service injects to the rpeository if it is a query , but the problem is not the controler, The problem is the dynamic nature of the query itself.

Would I be able to create more flexible queries so I dont have to have

getEmail($email)

getPhone($phone)

getId($id)

but rather

get$param)

Does it make sense?

gustav1105 started a new conversation How To?

I have been struggling trying to find a suitable solution to work with the back end dynamically, I am using vue on the front end and this gives me a lot of flexibility when it comes to my routes and controllers, but I have this dillema. The application I am working on is quite large or better put aspiring to be quite large, but architecture is getting me down. So a here is a little that needs to go a long way.

I will be reusing classes and thus these classes need to be flexible. For instance here we have two models

Users
Profiles

On the front end these two models need to be used either as each or as a combination of the two, or where relevant only parts of one or the other or a combination of parts of each.

Righto!

So considering I have eloquent available and am trying to find a suitable idea on forming the repository and services so things are structured that they can be reused.

But I still find myself in effect only creating wrappers for the classes that are essentially also concrete, for example.

When quering an email address or phone number from the partaining models, I have in a controller

public function getEmail($emal) {}

public function getPhone($phone){}

This just wont do! My thinking is as follows expanding on the above, in the controller i can also have

public function get($id)

So here we have three controller methods that are in a way exactly the same the difference is only the paramater.

Thus in my repository the queries will be

for the id

public function find($id)
{

return User::find($id);

//or

return User::where('id',$id)->first();
}

So for the email it is exactly the same the only difference i s

return User::where('email',$email);

So this sucks right?

I am redoing the same thing just with different params.

is there any way that I can make this more dynamic

so it could be something like

public function get($attr,$property)
{
 retur User::where($attr,$property)->first();
}

and can it be done to make it even more dynamic for example

I want all of these to be dynamic

->first() //so I can specify from my api call that it is first(0 or get()

User:: //Can specify from my api that it might be User or Profile Model

Any help or guidance will be cherished, Or even just a slight nudge in the right direction if I am going all wrong about his,

The issue is that trying to stay within the bounds of single responsibility that my controller wil have the following methods

public function index(){}

public function create(){}

public function update(){}

public function delete(){}

public function get{}

so I am trying t give these methods as much flexibility as I can when quering or writing to the database.

Is it possible if so how?

THANK YOU!

19 May
2 years ago

gustav1105 left a reply on Customer, Services And Prices

Looks fine to me.

gustav1105 left a reply on Unexpected Constant Condition No-constant-condition

Hi,

Just a tip if you want to post code put your code inside ```

so your code will be

methods: {
 alert: function () { this.$emit('onoff') }
 },

 created () {
 this.$on('onoff', function () 
{ if ('gender' === ' ' || 'age' === ' ' || 'activity' === '' || 'weight' === ' ') 
{ return 'true' } else { return 'false' } } ) }

revised

export default {

data() {

return {
gender: ' ',
age:  ' ',
activity: ' ',
weight: ' '

}

},

methods: {

alert() {

this.$emit('onoff')

} },

created() {

//WHAT DO YOU WANT TO DO WITH THE CODE?

}

}

post your code!

gustav1105 left a reply on API Error

Can't do much if your code is not shown

gustav1105 left a reply on Crud With No Index Or Create?

I would recommend you start looking into programming in a Restful pattern and using API calls from your front end to interact with your backend.

Then you don't have to adhere to such regulations and you can specify your end points.

This free's you from submit requests via php.

And gives you ajax ability instead.

gustav1105 left a reply on Vue Axios Refresh

Why do you want to refresh every 30 seconds, what do you want to achieve?

There might just be a better way..

18 May
2 years ago

gustav1105 left a reply on IsEmpty () Method Does Not Work

@empty($order)
     $order is empty
@endempty

gustav1105 left a reply on Search For More Than One Things In One Search Bar?

It is possible but you will need a search driver like elasticSearch and you will have to migrate the fields you want searchable so that elastic search can pick up on them them.

Good search functionality is no walk in the park. but elastic search makes it easier and it is free,

You will need to setup an account and have to pull in the dependencies.

Without a package like this, search is only a query that you write and maintain, if your app grows a lot it will get messy. You might also take the query route and create a repository and interfaces for your search this might keep things tidy.

Best of luck.

gustav1105 left a reply on Retaining Form Data

use

<keep-alive>
<router-view></router-view>
</keep-alive>

gustav1105 left a reply on Concatenate Two Variable In View.blade.php

{!! $glycemie->medecingeneraliste->personnel->civilite' + '$glycemie->medecingeneraliste->personnel->nom!!}
17 May
2 years ago

gustav1105 left a reply on Passport API ?

@noji, why not just use vue with passport?

I always use vue with passport..

gustav1105 left a reply on After Installing Bulma Through NPM, How Can I Use/refer It In My Project

you need to change the path to your scripts in your layout file

or wherever you use your scripts

laravel mix will compile your assets but in order to acomplish this

change the

<script asset="app.js'> to  mix="app.js"

do the same for your css file

now when you run

npm run  dev

your assest scss and js are compiled to a file app.js in your public directory.

when you install via npm in the way you have you will have it available, you might need to import it in your bootstrap.js file I am not sure, see bulma docs.

gustav1105 left a reply on Passport API ?

Oh yes off course, have you got http guzzle installed? and then the laravel docs does show you how to create a passport grant without vue as well.

gustav1105 left a reply on Passport API ?

Go to app/Http/Kernel.php and add this new middleware to web:

\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,

16 May
2 years ago

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

@idcreatv

Sorry could not get it done for you using vue. Well best of luck then, o yeah just remember when posting reply's to someone just prefix the user with the @ sign, otherwise the receiver of the message will not be notified by laravel.

gustav1105 left a reply on Auth Attempt Fails If Username Is Not Unique

@jochensengier The login controller uses a trait go to the trait and see if you can make the adjustments there

see documentation

https://laravel.com/docs/5.4/authentication#login-throttling

gustav1105 left a reply on Vue User Interface

I use bootstrap. It's not the best they say but I know it well and haven't encountered much resistance from bootstrap when using vue.

gustav1105 left a reply on How To Trigger A Form Submission From A Modal?

ajax post using axios

axios.post('/save', { firstName: 'first', lastName: 'last' })
  .then(function(response){
    console.log('saved successfully')
  });  

gustav1105 left a reply on Invalid Expression. Generated Function Body

The curly braces can't be used inside vue for instance

<div id="{{your.id}}></div>

above is wrong

rather bind the attribute.

<div :id="your.id"></div>

gustav1105 left a reply on Laravel Mix Creates A Mix.js, But Why?

What do you need to configure?

Just change asset to mix in you html

<script src="mix(app.js)"></script>

do the same for css.

gustav1105 left a reply on Define V-model Through Component Tag

You are calling v-model on name but name is not in your data property

gustav1105 left a reply on Frontend Input Validation Based On Json Api?

+1 Following! Would love to know if this question has an answer.

So much frustration, having to validate both on front and back end.

gustav1105 left a reply on Auth Attempt Fails If Username Is Not Unique

Go to the Auth controllers in your registerUser or create User you will find a validation where you create a new user it will have a rule

something like

username => required|unique

Simple remove the unique.

If you wan to read more about it check laravel docs, requests validation.

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

@idcreatv Did the solution work or have you done something else, please post so that others might have a solution also.

15 May
2 years ago

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

There is a course on Udemy https://www.udemy.com/vuejs-2-the-complete-guide

this will help you a lot.

Anyway, if you want to leverage the full power of vue, you should create vue components you can register them in your app.js file look at the example vue component that ships with laravel, then you can use that custom component on your blade file, so all your vue related stuff will be done there,

it takes some set up I know I have suffered through it alone, so If you wish i can help you do that, it is quite easy once you uderstand it.

What we can try is to use a method to set the id on the data property

data: {
    
    receiveEmployee: ' ',


}

methods: {

      addAttendee: function(id){
                console.log(id);
                axios.post('/courses/attendees/'+ this.receiveEmployee)
                .then(response => {
                    this.newAttendees.push(this.newAttendee)
                    console.log(response.data);
// This is the part I'm struggling with - the =id part is just returning the actual {{ employee.id }} string rather than the number
                })

}
<button v-on:click="addAttendee"
 v-model=" recieveEmployee" 
value="@{{ receiveEmployeeId }}"
class="danger btn btn-default btn-xs">
<i class="fa fa-plus-circle" aria-hidden="true">
</i>
</button>

I have not tested the above as to give quick answers, but here is my thinking.

Use v-model to bind the output of value to a data property the reference the the data property this.dataproperty in your method..

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

The problem as I can best describe is you are trying to use blade and vue together, and then things tend to get error prone.

We are trying to bind a vue property to a blade property and your blade is trying its best to figure it out but can't because

:receiveEmployeeId="@{{ recieveEmployee.id }}"

this does not resolve well.

I should of thought of that sorry!

Let me just quickly try and find a quick solution!

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

@idcreatv

// This is the part I'm struggling with - the +id part is just returning the actual {{ employee.id }} string rather than the number//

It will output a string because of the double braces. They strip the tags and remove whitespace, its to protect agains xss injection.

Try my solution let me know if it is not clear will try and clarify or what errror you are getting

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

<td>
<button :receiveEmployeeId="{{ recieveEmployee.id }}"
v-on:click="addAttendee(receiveEmployeeId)" class="danger btn btn-default btn-xs">
<i class="fa fa-plus-circle" aria-hidden="true"></i>
</button>
</td>
<script>

props:['receiveEmployeeId'],

methods: {

       addAttendee: function(id){
                console.log(id);
                axios.post('/courses/attendees/'+id)
                .then(response => {
                    this.newAttendees.push(this.newAttendee)
                    console.log(response.data);
// This is the part I'm struggling with - the =id part is just returning the actual {{ employee.id }} string rather than the number
                })

}
</script>

something like that

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

In the meantime you can try sommething like

<select :employeeId="{{employee,id }}"></select

Then you have it available to use in vue

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

Ok Lets go through this.

Post your code please.

gustav1105 left a reply on Using Part Of A JSON Response As A Variable?

the syntax is wrong it should be somethinglike

v-on:click="addToCourse{{employee.id}}"

try it but I think vue is gonna give you error interploration in vue component has been removed or something or the other.

You could take the value you want and bind it to a prop.

Anyway let me know I will try and help. Just have to get home quick

gustav1105 left a reply on Migration Fails Due To Not Finding Class

Check your routes, make sure all of them are correct and working.

gustav1105 left a reply on How To Get Resource Data In Form Request

run artisan command

php artisan make:request ValidateResourcesRequest

this will create a class for you, inside this class set the authorize to true

write your rules for example

'email' => 'required|max:20'

in your controller at the top

''' use App\Requests\ValidateResourcesRequest '''

then type hint in your function

public function update(ValidateResourceRequest $request) 
{

$data = $request->all();

}

Thats that. Validation done on the post request data.

12 May
2 years ago

gustav1105 left a reply on Best Way To Handle This Relationship

Yes that sounds good! I can't see a problem with your logic.

gustav1105 left a reply on Clarify Eloquent For Me A Little Bit Please

@justnorris The best guide to understand how this works will in fact be to understand how laravel works,

https://laracasts.com/series/laravel-from-scratch-2017/episodes/23

Start with above tutorial and watch the subsequent two tutorials 24 and 25.

Here Jefrey explains the magic.

It all comes down to service providers and service containers and Dependency injection.

Laraval is essentially a IOC (service container) The videos might help for a clearer understanding.

The videos will not directly answer your question but might help.

gustav1105 left a reply on Public And Admin "sides" Of A Model

Why not use a ACL and on the html you can validate if a user as a role and according to that the results will differ?

gustav1105 left a reply on Preview Doc, Ppt And Pdf

All modern browsers have pdf reading capabilities.

gustav1105 left a reply on Clarify Eloquent For Me A Little Bit Please

public fuction index(Tag $tag)

Here you are method injecting (passing argument to a method) So here you can use $tag in posts

$posts = $tag->posts;

Here you are using it correctly, for example lets say you have a table Posts and the table Posts has a row tags,

this table posts has a model Post and this model you use in your controller for instance.

where at the top you

use App\Posts (the model)

Thus eloquent makes it available to you do operations on that table through the model.

so you are looking for a row tags in model posts.

 $posts = $tag->posts();

Wont work because now you are trying to make posts a method. Posts is not a method of $tag

gustav1105 left a reply on Explaining @section

I see it like this, use extend to extend your layout, for example you have your css and scripts and csrf tokens and your header that will be pulled into every page.

Use section where you would like to import a section of code to a page,

for example.

you have your main layout layout and on all of your other pages you will extend this main layout

and then you will have a section that you can include in on this page something like a sidebar.