richardh

Experience

2,250

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 9 Lessons Completed
  • 0 Favorites

15th May, 2018

richardh started a new conversation Relations On Column That Is An Array • 5 months ago

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

11th May, 2018

richardh started a new conversation SetAttribute In Model • 5 months ago

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);
    }

24th April, 2018

richardh left a reply on Set A Date In Model • 5 months ago

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 • 5 months ago

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()

16th April, 2018

richardh left a reply on Querying On Relations • 6 months ago

@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 • 6 months ago

no

richardh left a reply on Querying On Relations • 6 months ago

@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 • 6 months ago

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

    }

richardh started a new conversation Querying On Relations • 6 months ago

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 • 6 months ago

it returns 0 now where I am expecting 3

richardh started a new conversation Building Multiple Where Queries • 6 months ago

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.

29th March, 2018

richardh left a reply on Access Array In Object • 6 months ago

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 • 6 months ago

i get this Trying to get property of non-object

richardh started a new conversation Access Array In Object • 6 months ago

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

28th March, 2018

richardh left a reply on Redirect::to Passing Variable To View • 6 months ago

How do I then use my new session variable

richardh left a reply on Redirect::to Passing Variable To View • 6 months ago

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 left a reply on Redirect::to Passing Variable To View • 6 months ago

Im lost

richardh started a new conversation Redirect::to Passing Variable To View • 6 months ago

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.

20th March, 2018

richardh started a new conversation Mark All Fields From A Query • 6 months ago

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

15th March, 2018

richardh left a reply on JWT Returning Token • 7 months ago

Changed my headers to application/json works now :)

richardh started a new conversation JWT Returning Token • 7 months ago

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 • 7 months ago

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

richardh started a new conversation Check When A Query Was Successful • 7 months ago

How would I check this query was successfully executed:

 DB::table('private_messages')->whereIn('id', $remove_ids[0])->delete();

2nd March, 2018

richardh left a reply on Updating Array Saves Back As Object • 7 months ago

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

richardh left a reply on Updating Array Saves Back As Object • 7 months ago

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

richardh started a new conversation Updating Array Saves Back As Object • 7 months ago

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.

1st March, 2018

richardh left a reply on Casting To Boolean • 7 months ago

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 • 7 months ago

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.

27th February, 2018

richardh started a new conversation Search Array In Column To Bring Back Matches From Array Submitted • 7 months ago

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.

23rd February, 2018

richardh left a reply on Send An Array Of ID's To Database • 7 months ago

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 • 7 months ago

I just get invalid argument supplied to foreach()

richardh left a reply on Send An Array Of ID's To Database • 7 months ago

Can I just send the array as is

richardh started a new conversation Send An Array Of ID's To Database • 7 months ago

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.

20th February, 2018

richardh started a new conversation How To User ForeignKey And OwnerKey • 7 months ago

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

9th January, 2018

richardh left a reply on Convert Object To Array - Mailable • 9 months ago

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

richardh left a reply on Convert Object To Array - Mailable • 9 months ago

How should I send the $question

richardh started a new conversation Convert Object To Array - Mailable • 9 months ago

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.

8th January, 2018

richardh started a new conversation Counting Different Types In A Column • 9 months ago

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');

30th November, 2017

richardh left a reply on Sending Email • 10 months ago

Solved the issue.

richardh left a reply on Sending Email • 10 months ago

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 • 10 months ago

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

9th October, 2017

richardh started a new conversation Homestead - Cannot See Database Tables • 1 year ago

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.

4th October, 2017

richardh started a new conversation Add Default Option To Select • 1 year ago

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

20th September, 2017

richardh left a reply on Changed Database Details In .env Now Have RuntimeException • 1 year ago

it is cartalyst i have now found out

richardh started a new conversation Changed Database Details In .env Now Have RuntimeException • 1 year ago

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.

19th September, 2017

richardh left a reply on Pass Variables To @include Array • 1 year ago

Thank you this has fixed my problem

richardh started a new conversation Pass Variables To @include Array • 1 year ago

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')])
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.