alex-greaves

Experience

3,560

2 Best Reply Awards

  • Member Since 2 Months Ago
  • 24 Lessons Completed
  • 0 Favorites

22nd June, 2017

alex-greaves left a reply on How To Redirect A Form With Post Method When Validation Fails? • 1 month ago

Can you please clarify what happens when you submit a form with validation errors, and what you want to happen?

From your question it sounds like there is no problem. You said 'When i am trying to update a user having unique email, the validation fails and its showing error like email already exists.' So it shows the validation errors. I don't see what you need to happen.

16th June, 2017

alex-greaves left a reply on How To Use Bootstrap Datepicker In Laravel 5.2 • 2 months ago

Use Carbon to find the difference:

http://carbon.nesbot.com/docs/#api-difference

alex-greaves left a reply on How To Use Bootstrap Datepicker In Laravel 5.2 • 2 months ago

https://bootstrap-datepicker.readthedocs.io/en/latest/

**Requirements**
Bootstrap 2.0.4+
jQuery 1.7.1+

Add a class to an input e.g. 'datepicker' and initialise datepicker on that class in jQuery:

$('.datepicker').datepicker();

15th June, 2017

alex-greaves left a reply on Separate Profile Table For Candidate And Company • 2 months ago

Can you expand on what you want to retrieve? currently you just need a belongsTo relationships on the candidates and companies tables and you can retrieve that data from a user.

13th June, 2017

alex-greaves left a reply on Cannot Stream Laracast Videos • 2 months ago

All good for me, are you able to view videos on a different device?

alex-greaves left a reply on Show Friendly 500 Error And Also Display Database Errors Friendly • 2 months ago

You can overwrite any Laravel error views by just creating a view for them:

https://laravel.com/docs/5.4/errors#custom-http-error-pages

e.g. to create a custom 500 error page create the view:

resources/views/errors/500.blade.php

alex-greaves left a reply on Pass Data From Ajax To Controller Via Post And Back To Blade • 2 months ago

What you'll need to do is return a JSON response with the required data.

Judging by your js so far you want to just put pre-formatted HTML into the empty div in which case you'd want to create a new view and format the cities, render that view and return it as a JSON response. Something along the lines of the below:

HomeController.php

public function getCities()
{
    $request = Request::all();
    $cities = City::where('country_id', $request->id)->get();

    $html = view('layouts.partials.cities')->with(compact('cities'))->render();
    return response()->json(['success' => true, 'html' => $html]);
}

views/layouts/partials/cities.blade.php

Here you will have the cities and you will need to format them.

Then update your Javascript to:

$(document).ready(function(){
    $('#countires').change(function(){
        var id = $(this).val();
        $.ajax({
            url: baseUrl+"/get-cities/",
            method: "POST",
            data:{id:id},
            success: function(data){
                $('#show_cities').html(data.html);
            }
        });
    });
});

I would however suggest you change the ajax route you're posting to and instead use a get request. You aren't posting data, you're getting data i.e. the cities. Something along the lines of:

$(document).ready(function(){
    $('#countires').change(function(){
        var id = $(this).val();
        $.ajax({
            url: baseUrl + "/get-cities/" + id,
            method: "GET",
            success: function(data){
                $('#show_cities').html(data.html);
            }
        });
    });
});

alex-greaves left a reply on Property [user] Does Not Exist On This Collection Instance. • 2 months ago

You may have set this up differently for whatever reason, but on your User model it should be - unless for some reason you have a user_id on your user table:

public function characters()
{
    return $this->hasMany(Character::class, 'user_id', 'id');
}

and your characters model should be:

public function user()
{
    return $this->belongsTo(User::class, 'user_id', 'id');
}

alex-greaves left a reply on Keep Redirecting Me To The Homepage • 2 months ago

Can you please explain what the issue is exactly, from my understanding you want the following:

  1. After completing User Registration.

    • Login the user
    • Redirect to the homepage
  2. When a user logs out

    • Log the user out
    • Redirect to the homepage

Are you saying: all the above criteria is met except when you try to log the user out, they get redirected to the homepage but remain logged in?

alex-greaves left a reply on Undefined Variable: Tasks • 2 months ago

Can you please show where you're setting the tasks variable and where you're passing it to the view?

alex-greaves left a reply on Retrieving Data From Array • 2 months ago

This may well be to do with your query

$postcode = collect(Postcode::postcodeLookup($location->post_code))->all();

you're doing all(); rather than get();

12th June, 2017

alex-greaves left a reply on No Query Results For Model [App\\Document] • 2 months ago

@CodebyRay I don't think it is caused by the call to the API because his error is that there are no results for the query so it is at least running the query.

@dantekavala Try hitting Document::all(); instead of your current query and see if there are any results. If there are results check there are results which match your criteria i.e. they have 'null' in the expired field. If not check there are records on your documents table.

11th June, 2017

alex-greaves left a reply on Pass Value To Laravel Named Routing From Javascript • 2 months ago

My response doesn't require VueJS. Replace is a basic Javascript function https://www.w3schools.com/jsref/jsref_replace.asp

alex-greaves left a reply on Pass Value To Laravel Named Routing From Javascript • 2 months ago

var url = '{{ route("admin.edit_school", ":slug") }}'; url = url.replace(':slug', slug); window.location.href=url;

alex-greaves left a reply on How To Store Changed Form Input In Database • 2 months ago

The way you go about it depends on what you need it for and how it is you're changing the input.

For example if you were storing a text input but for whatever reason you wanted to make sure the text stored was all lowercase when creating a record you could just pass an array to the create method and set the values there rather than passing the input.

So rather than doing something like: $post->create($request->all());

You could do this: $post->create([ 'name' => strtolower($request->input('name')) ]);

alex-greaves left a reply on BadMethodCallException In Macroable.php Line 74: Method Specialization Does Not Exist • 2 months ago

The issue here is that you're calling a specialization method on the request class which doesn't exist.

Judging by the code I presume you're posting a form to create a doctor. So you need to set the spec_id equal to a value from the form or at least from somewhere it exists, your commented out version '$doctor->spec_id = $request->input('spec_id');' should work as long as there is an input with a name of 'spec_id'.

Also why are you trying to set a spec_id on the doctor? You've created a has many relationship so that a doctor can have many specializations, but by having a spec_id on the doctor you're limiting it to having 1 spec, instead there should be a doctor id on the specialization. I'm not sure about your business logic but to be honest this should be a pivot table so the specializations are re-usable.

Edit Your Profile
Update

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