richardh

richardh

Member Since 1 Year Ago

Experience Points 2,250
Experience
Level
Lessons Completed 9
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

15 May
6 months ago

richardh started a new conversation Relations On Column That Is An Array

Is there a way of joining on a column where it is and array on intergers. I want to try and do this

    public function students(){
        return $this->hasMany('App\Api\Models\User', '[group_ids]', 'id');
    }

'[group_ids]' is an array. how could I make the query work

11 May
7 months ago

richardh started a new conversation SetAttribute In Model

I want to set a random string for a column in the database, thought i would use a mutator.

Ho do I use the $value in the below example:

public function setSchoolCodeAttribute($value){
        $this->attributes['school_code'] = str_random(8);
    }
24 Apr
7 months ago

richardh left a reply on Set A Date In Model

I have gone for this approach do you think it will be ok?

 if($request->has('ofs')){
            $data['ofs_updated'] = \Carbon\Carbon::now();
        }

richardh started a new conversation Set A Date In Model

I was wondering how would I set the date in the model when there was a certain input present.

For example i am updating a model and wanted to set the date to now()

16 Apr
7 months ago

richardh left a reply on Querying On Relations

@tykus the column type is not a JSON column, yes the group_ids is an array in the uSers table. Thank you

richardh left a reply on Querying On Relations

@tykus I want to return all the posts where the group_id that belongs to the post table, is in the [group_ids] that are in the User table. So the post has a group_id and the users group_ids need searching for the post->group_id

richardh left a reply on Querying On Relations

    {
        return $this->hasOne('App\Api\Models\User', 'id', 'post_user_id');

    }

richardh started a new conversation Querying On Relations

I have a Post table where the group_id on the Post is a single value. The table has a relation to a User table where the group_ids are an array in the column. I am trying to use this query but ...

$posts = Post::where('school_id', $school_id)
                    ->user()->whereIn('group_id','group_ids')
                    ->Ordered()
                    ->paginate(20);

but the response I get is :

"Call to undefined method Illuminate\Database\Query\Builder::user()"

How would I use the relation to check the User [group_ids]

richardh left a reply on Building Multiple Where Queries

it returns 0 now where I am expecting 3

richardh started a new conversation Building Multiple Where Queries

I am querying a table where the read column is either 1, 0 or nullwhen i query the database I cant seem to include the null result it doesnt count it.

$total = Notification::where('user_id', $request->authedUser->id)
            ->where('read', '!=', 1)
            ->where('read','=',null)
            ->count();

The ->where('read','=',null) doesn't seem to return the null columns How can I write the query to include that result.

29 Mar
8 months ago

richardh left a reply on Access Array In Object

it comes back from this call $company_categories = $req->get('company-categories')->json();

I use compact to send it to the view

richardh left a reply on Access Array In Object

i get this Trying to get property of non-object

richardh started a new conversation Access Array In Object

I have a response that returns an object with an array, I want to use this in a select for the options when I DD the variable in the view it looks like:

{
    $company : array[]
}

in the select I have :

 @foreach($company as $companyCategory)
              <option value="{{ $companyCategory['id'] }}">
                                 {{ $companyCategory['name'] }}</option>
 @endforeach 

I always get undefined index id which must be the $companyCategory['id'] how can I use this in the select

28 Mar
8 months ago

richardh left a reply on Redirect::to Passing Variable To View

How do I then use my new session variable

richardh left a reply on Redirect::to Passing Variable To View

In the MainController it just returns: return $donation but there is a laravel api call that looks like this: $res = $this->api->post('donation/create', $request->all())->json(); this then posts to the MainController should I be sending my return fro the MainController

richardh started a new conversation Redirect::to Passing Variable To View

I have need to send some data back to the view from a function that returns this: return Redirect::to($request->input('success_url')); I have tried using ->with but I always get the error $donation is not defined I also tried compact but same issue return Redirect::to($request->input('success_url'), compact('donation',[$res]));

Is there a way to return data back so i can use it in my view.

20 Mar
8 months ago

richardh started a new conversation Mark All Fields From A Query

I have a column in a database where the I want to search user_id and mark all fields when I get the result. I am not sure how to mark all the fields when I have to data.

my query :

            $user = PrivateMessage::where('recipient_id', '=', $request->authedUser->id)->get();

then I want to set PrivateMessage->read = 1

how would I do this

15 Mar
8 months ago

richardh left a reply on JWT Returning Token

Changed my headers to application/json works now :)

richardh started a new conversation JWT Returning Token

I have set up a project according to http://jwt-auth.readthedocs.io/en/develop/laravel-installation/ Laravel JWT when I submit to the login with postman I get all the information

"access_token": "eyJ0eX... ...",
    "token_type": "bearer",
    "expires_in": 3600

When I submit from an app I have put together I get

    "access_token": false,
    "token_type": "bearer",
    "expires_in": 3600

The headers I am sending from my app are

'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': '*/*',
            'Authorization': authorise

the Authorization at this point is null as I have never had a token, I have tried sending the request without but it doesn't change anything.

What headers do people send who are using the JWT service.

richardh left a reply on Check When A Query Was Successful

would I do something like if (!delete()) ?

richardh started a new conversation Check When A Query Was Successful

How would I check this query was successfully executed:

 DB::table('private_messages')->whereIn('id', $remove_ids[0])->delete();
02 Mar
9 months ago

richardh left a reply on Updating Array Saves Back As Object

Hi Guys thanks for you help (array)before the variable did it :)

richardh left a reply on Updating Array Saves Back As Object

its still turned it into an object, I want an array.

richardh started a new conversation Updating Array Saves Back As Object

I am removing id's from an array in a column in the database, when I save it back it is then an object in the column instead of an array. I am using the $casts to cast the column to array.

 $teacher = User::find($teacher_id);
        $groupIds = $teacher->group_ids;
        $key = array_search($teacher_id, $groupIds);

        unset($groupIds[$key]);
//        dd($groupIds);
        $teacher->group_ids = $groupIds;
        $teacher->save();

At the dd() it is still an array. Then I see an object with a string as the index instead of a number.

01 Mar
9 months ago

richardh left a reply on Casting To Boolean

I had to add this as well

       $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);

richardh started a new conversation Cast Json True To Boolean In The Model

I have an json call that sends 'true' as a property and get the error

  "message": "SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'true' for column 'suspended'

I have tried to use the

 protected $casts = [
       'suspended' => 'boolean'
    ];

but this doesn't work either .

Does anybody know how this is achieved.

27 Feb
9 months ago

richardh started a new conversation Search Array In Column To Bring Back Matches From Array Submitted

I have a json api I am sending queries to. I send the query which looks like this

{"ids":"[1,3,4,5,6]"}

my Function to handle the request

public function teachersInGroup(Request $request)
    {
        $array = json_decode($request->ids);

//       dd($request);
 dd($array);
        $users = User::whereIn('group_ids', $array)->get();
        dd($users);
        return response()->json($users, 200);
    }

When I dd($array) I see a properly formed array

array:5 [
    0 => 1
    1 => 3
    2 => 4
    3 => 5
    4 => 6
]

The whereIn query (i think) is querying the 'group_ids' which has the ids being sent in but never returns any users. I though it would match the groups Ids to the array being passed in and return full rows, which would contain the users I am looking for.
23 Feb
9 months ago

richardh left a reply on Send An Array Of ID's To Database

IF I just put the array[1,2,3] in the argument for the whereIn it works. when I send my request from the app and check it PAW (restful service tester)

"[3,4,5]"

it looks like this

richardh left a reply on Send An Array Of ID's To Database

I just get invalid argument supplied to foreach()

richardh left a reply on Send An Array Of ID's To Database

Can I just send the array as is

richardh started a new conversation Send An Array Of ID's To Database

How would I send an array to the database to the query and return all the users with the ids I sent.

I have an API with is powered by laravel, I already have the array of ids on the page, I am sure how to send the array to the server.

If I use a post method How do I sort the data in the controller.

Any pointers would be great thanks.

20 Feb
9 months ago

richardh started a new conversation How To User ForeignKey And OwnerKey

I have a Grade model that belongs to a User. So in my User I have a function

    public function grades()
    {
        return $this->hasMany('App\Api\Models\Grade', 'user_id', 'id');
    }

The user_id is a foreignKey in the Grade model. When I want to get a Grade I want to bring the User data back with it, but I cant manage it :).

In my Grade model I have:

    public function user()
    {
        return $this->belongsTo('App\Api\Models\User', 'user_id', 'id');
    }

the foreignKey I take it must be the key in the Grade table and the id must be the key in the User table, I have tried every combination I can think, but there must be some simple logic to this.

In my GradeController I am passing in an id to get the Grade,

 $grade = Grade::find($id);
        $gradeUser = $grade->user();

I am trying to assign $gradeUser but never get a User

09 Jan
11 months ago

richardh left a reply on Convert Object To Array - Mailable

I think the problem is the mail is the same name as my class

richardh left a reply on Convert Object To Array - Mailable

How should I send the $question

richardh started a new conversation Convert Object To Array - Mailable

I have an API where I am sending in an object, do the changes and then I want to send a mail to the user saying the response has been made.

The last part of my Controller is below

 $question = TechQuestion::find($id);
...
...
  $question->fill($request->all());
        $question->save();

        Mail::to($question->user_email)
            ->send(new TechQuestion($question));

The error I am getting is for the send() $question being an object.

How would I change this to an array? I have tried calling ->toArray() but does not work.

08 Jan
11 months ago

richardh started a new conversation Counting Different Types In A Column

I have a column in a table where I need to count all types that are X and all types that are Y,

$allUpdatesCount = News::count('type');

This works ok, I want to count the types that = a certain type ,I am trying the below but not sure the correct syntax

        $propertyAmaCount = News::count('type','property_ama');
30 Nov
1 year ago

richardh left a reply on Sending Email

Solved the issue.

richardh left a reply on Sending Email

class EnquiryCreated extends Mailable
{
    use SerializesModels;

    public $enquiry;

    /**
     * Create a new message instance.
     *
     * @param Enquiry $enquiry
     */
    public function __construct(Enquiry $enquiry)
    {
        $this->enquiry = $enquiry;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from(env('MAIL_SENDER'))
                    ->view('mail.enquiry')
                    ->with([
                        'enquiry' => $this->enquiry
                    ]);
    }
}

richardh started a new conversation Sending Email

I am trying to send an email, (Second time ever) and I keep getting

in Mailable.php (line 458)

The Request is

 $enquiry = Enquiry::create([
            'email' => $email,
            'data' => $data
        ]);

that I am passing to

Mail::to(env('MAIL_SENDER'))->send(new EnquiryCreated($enquiry));

Could anybody tell me where I am going wrong as all the Mailable properties seem to be null(this makes me think something is missing), I have my .env set up. I have changed my config.mail.php

I don't know what to try

09 Oct
1 year ago

richardh started a new conversation Homestead - Cannot See Database Tables

I have a site running on Vagrant, I am on Mac. I use sudo to vagrant up, use vagrant ssh to go to the Code folder and then run php artisan migrate I have gone with all the defaults to try and get the database tables to show. When I connect through sql pro the tables never show up. I have tried for 3 nights. I have installed the vagrant bindfs plugin.

Here is my Homestead.yaml

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: /Applications/MAMP/htdocs/laravel/rhtest
        to: /home/vagrant/Code
        type: "nfs"
sites:
    -
        map: rhtest.app
        to: /home/vagrant/Code/public
databases:
    - homestead
name: rhtest
hostname: rhtest
ports:
    - send: 63790
      to: 6379
      protocol: udp

my .env is just the normal.

I'm wondering if it is a permissions problem for the DB. Any suggestions would be great.

04 Oct
1 year ago

richardh started a new conversation Add Default Option To Select

I have seen many examples of adding a default option to the select but none for the way I am using.

                                @foreach($recipient_ids as $recipient_id)
                                    <option value="{{$recipient_id['id']}}">{{$recipient_id['name']}}</option>
                                @endforeach
                            </select>```

Is there an easy way to add the option?

Thanks
20 Sep
1 year ago

richardh left a reply on Changed Database Details In .env Now Have RuntimeException

it is cartalyst i have now found out

richardh started a new conversation Changed Database Details In .env Now Have RuntimeException

I added a new database and changed the .env to point at this DB refreshed the page and have the error

No active theme has been set.

I have had a google and could not find anything. Has anybody had this problem before.

19 Sep
1 year ago

richardh left a reply on Pass Variables To @include Array

Thank you this has fixed my problem

richardh started a new conversation Pass Variables To @include Array

I was wondering how I could use the variable if set or a default value. I am working on an existing project and new to laravel.

 {{dd($vehicle)}}
            @include('partials.finance-calculator',[
            'price' => @if(isset($vehicles->price)) ? $vehicles->price : '25000' @endif,
             'deposit' => '5000', 'term' => '', 'year' => date('Y')])