clat23

Experience

6,020

0 Best Reply Awards

  • Member Since 9 Months Ago
  • 53 Lessons Completed
  • 0 Favorites

21st March, 2017

clat23 left a reply on Bootstrap Styling Looks Different With Laravel Spark? • 6 days ago

@douglas_quaid I followed Gorby's suggestion of editing the styles in app.css

I googled "twitter bootstrap colors" for hex codes to get the correct color codes.

1st March, 2017

clat23 left a reply on Routing To A Controller Within A Route Function • 3 weeks ago

Thanks @Snapey !

clat23 left a reply on Routing To A Controller Within A Route Function • 3 weeks ago

Thanks @Cronix I had the logic in my [email protected] but I felt it was getting very messy so I thought I'd separate it. I think I'll go with putting it in a middleware.

clat23 started a new conversation Routing To A Controller Within A Route Function • 3 weeks ago

I want to route to a view if a user's api token is expired and route to a controller if it's not. Here's my routes.php

Route::get('/sales/pending', function () {
    $now = Carbon::now();
    $expiration = Carbon::createFromFormat('Y-m-d H:i:s', Auth::user()->api_token_expiration);
    $expired = ($now->gt($expiration));
    if($expired == true){
        return view('/sales/token-expired');
    } else {
        return controller([email protected]'); //This is what's giving me an error
    }
});

First of all, is this the best place to have this kind of logic? If so, how do I have the routes file point to the [email protected] controller when the user's token is expired?

clat23 left a reply on Bootstrap Styling Looks Different With Laravel Spark? • 3 weeks ago

Well, I took my non-Spark Laravel app.css and overwrote the app.css in Laravel Spark and the result was no styling whatsoever. So there goes that idea. I also looked at my non-Spark app.css and the styling for the .thumbnail background was also gray there too and same problems with the btn-warning. So is Laravel Spark not entirely pulling from app.css?

clat23 left a reply on Bootstrap Styling Looks Different With Laravel Spark? • 3 weeks ago

I found the .thumbnail and btn-warning styling in app.css and changing them worked. But now, it makes me wonder what else is off. Would it be safe to take the app.css from my non-Spark install of Laravel and overwrite my Laravel Spark's app.css?

Also what do you mean by "my template css"? Is this your app.css? And what do you mean by "Spark default"? Is this Spark's version of app.css?

28th February, 2017

clat23 started a new conversation Bootstrap Styling Looks Different With Laravel Spark? • 3 weeks ago

I recoded my app from a Laravel 5 installation to a new Laravel Spark installation. However I noticed that some of the bootstrap styling is off.

Take for example a bootstrap thumnail:

<div class="row">
  <div class="col-sm-6 col-md-4">
    <div class="thumbnail">
      <img src="..." alt="...">
      <div class="caption">
        <h3>Thumbnail label</h3>
        <p>...</p>
        <p><a href="#" class="btn btn-warning" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
      </div>
    </div>
  </div>
</div>

In my Laravel 5 installation the thumbnail background is white. But in the Laravel Spark installation, the thumbnail background is gray.

Furthermore, the btn-warning button is yellow/green when it's supposed to be orange. There's no problems with the other buttons such as btn-primary and btn-success --- these buttons have blue and green styling respectively.

Does anyone know what is causing this?

21st February, 2017

clat23 started a new conversation What Is The Purpose Of Handler.php? • 1 month ago

I have read the following documentation:

https://laravel.com/docs/5.4/errors#the-exception-handler

However, it doesn't go into detail on when the exception handler is used. Currently I am creating custom exceptions in App/Exceptions then I Use App/Exceptions/CustomException in my controller that has try/catch blocks.

Here's some sample code:

SomeController.php:

use App\Exceptions\CantDoException;
                          //use App\Exceptions\Handler;

                          function doSomething()
                          {
                              throw new CantDoException('Unable to do that something');
                          }

                          try {
                              doSomething();
                          }
                          catch(CantDoException $e)
                          {
                              print $e->getMessage();
                          }

App/Exceptions/CantDoException.php:

<?php

namespace App\Exceptions;
use Exception;

class CantDoException extends Exception {}

The above sample code works just fine for me. So what's the point of using the Exception Handler in Handler.php?

19th February, 2017

clat23 left a reply on ReflectionException In RouteSignatureParameters.php • 1 month ago

Figured it out. Turns out it was just a stupid syntax mistake on my part. There's a missing array closure bracket at the end of SetTimezone.php

clat23 left a reply on ReflectionException In RouteSignatureParameters.php • 1 month ago

It might be worth mentioning that I am using Laravel Spark. I know there are some differences there, but I have checked and double checked. This has really stumped me. Anyone have any idea on what I'm doing wrong?

18th February, 2017

clat23 left a reply on ReflectionException In RouteSignatureParameters.php • 1 month ago

Sorry. Here you go, SetTimezone.php:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SetTimezone extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'timezone' => [
                'required',
                Rule::in([
                    'Pacific/Midway',
                    'Pacific/Samoa',
                    'Pacific/Honolulu',
                    'US/Alaska',
                    'America/Los_Angeles',
                    'America/Tijuana',
                    'US/Arizona',
                    'America/Chihuahua',
                    'America/Chihuahua',
                    'America/Mazatlan',
                    'US/Mountain',
                    'America/Managua',
                    'US/Central',
                    'America/Mexico_City',
                    'America/Mexico_City',
                    'America/Monterrey',
                    'Canada/Saskatchewan',
                    'America/Bogota',
                    'US/Eastern',
                    'US/East-Indiana',
                    'America/Lima',
                    'America/Bogota',
                    'Canada/Atlantic',
                    'America/Caracas',
                    'America/La_Paz',
                    'America/Santiago',
                    'Canada/Newfoundland',
                    'America/Sao_Paulo',
                    'America/Argentina/Buenos_Aires',
                    'America/Argentina/Buenos_Aires',
                    'America/Godthab',
                    'America/Noronha',
                    'Atlantic/Azores',
                    'Atlantic/Cape_Verde',
                    'Africa/Casablanca',
                    'Europe/London',
                    'Etc/Greenwich',
                    'Europe/Lisbon',
                    'Europe/London',
                    'Africa/Monrovia',
                    'UTC',
                    'Europe/Amsterdam',
                    'Europe/Belgrade',
                    'Europe/Berlin',
                    'Europe/Berlin',
                    'Europe/Bratislava',
                    'Europe/Brussels',
                    'Europe/Budapest',
                    'Europe/Copenhagen',
                    'Europe/Ljubljana',
                    'Europe/Madrid',
                    'Europe/Paris',
                    'Europe/Prague',
                    'Europe/Rome',
                    'Europe/Sarajevo',
                    'Europe/Skopje',
                    'Europe/Stockholm',
                    'Europe/Vienna',
                    'Europe/Warsaw',
                    'Africa/Lagos',
                    'Europe/Zagreb',
                    'Europe/Athens',
                    'Europe/Bucharest',
                    'Africa/Cairo',
                    'Africa/Harare',
                    'Europe/Helsinki',
                    'Europe/Istanbul',
                    'Asia/Jerusalem',
                    'Europe/Helsinki',
                    'Africa/Johannesburg',
                    'Europe/Riga',
                    'Europe/Sofia',
                    'Europe/Tallinn',
                    'Europe/Vilnius',
                    'Asia/Baghdad',
                    'Asia/Kuwait',
                    'Europe/Minsk',
                    'Africa/Nairobi',
                    'Asia/Riyadh',
                    'Europe/Volgograd',
                    'Asia/Tehran',
                    'Asia/Muscat',
                    'Asia/Baku',
                    'Europe/Moscow',
                    'Asia/Muscat',
                    'Europe/Moscow',
                    'Asia/Tbilisi',
                    'Asia/Yerevan',
                    'Asia/Kabul',
                    'Asia/Karachi',
                    'Asia/Karachi',
                    'Asia/Tashkent',
                    'Asia/Calcutta',
                    'Asia/Kolkata',
                    'Asia/Calcutta',
                    'Asia/Calcutta',
                    'Asia/Calcutta',
                    'Asia/Katmandu',
                    'Asia/Almaty',
                    'Asia/Dhaka',
                    'Asia/Dhaka',
                    'Asia/Yekaterinburg',
                    'Asia/Rangoon',
                    'Asia/Bangkok',
                    'Asia/Bangkok',
                    'Asia/Jakarta',
                    'Asia/Novosibirsk',
                    'Asia/Hong_Kong',
                    'Asia/Chongqing',
                    'Asia/Hong_Kong',
                    'Asia/Krasnoyarsk',
                    'Asia/Kuala_Lumpur',
                    'Australia/Perth',
                    'Asia/Singapore',
                    'Asia/Taipei',
                    'Asia/Ulan_Bator',
                    'Asia/Urumqi',
                    'Asia/Irkutsk',
                    'Asia/Tokyo',
                    'Asia/Tokyo',
                    'Asia/Seoul',
                    'Asia/Tokyo',
                    'Australia/Adelaide',
                    'Australia/Darwin',
                    'Australia/Brisbane',
                    'Australia/Canberra',
                    'Pacific/Guam',
                    'Australia/Hobart',
                    'Australia/Melbourne',
                    'Pacific/Port_Moresby',
                    'Australia/Sydney',
                    'Asia/Yakutsk',
                    'Asia/Vladivostok',
                    'Pacific/Auckland',
                    'Pacific/Fiji',
                    'Pacific/Kwajalein',
                    'Asia/Kamchatka',
                    'Asia/Magadan',
                    'Pacific/Fiji',
                    'Asia/Magadan',
                    'Asia/Magadan',
                    'Pacific/Auckland',
                    'Pacific/Tongatapu'
                ])
        ];
    }
}

clat23 started a new conversation ReflectionException In RouteSignatureParameters.php • 1 month ago

I have created a new form request using php artisan make:request SetTimezone. I have followed the Laravel 5.4 documentation (https://laravel.com/docs/5.4/validation#creating-form-requests). However, I am getting this:

ReflectionException in RouteSignatureParameters.php line 25: Class app\Http\Requests\SetTimezone does not exist

Here's my SettingsController.php (end truncated):

<?php

namespace App\Http\Controllers;

// use Illuminate\Http\Request;
use Auth;
use App\Ebay;
use App\Paypal;
use Carbon\Carbon;
use Camroncade\Timezone\Facades\Timezone;
use App\Http\Requests\SetTimezone;

class SettingsController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');

        // $this->middleware('subscribed');
    }

    public function show()
    {
        Auth::user()->updateTokenStatus();
        return view('settings', Auth::user());
    }

    public function setTimezone(SetTimezone $request)
    {
        $newTimezone = request()->timezone;
        Auth::user()->setTimezone($newTimezone);
        return redirect()->action([email protected]');
    }

And here's my SetTimezone.php (created by php artisan make:request command) (also truncated):

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SetTimezone extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'timezone' => [
                'required',
                Rule::in([
                    'Pacific/Midway',
                    'Pacific/Samoa',
                    'Pacific/Honolulu',
                    'US/Alaska',
                    'America/Los_Angeles',
                    'America/Tijuana',
                    'US/Arizona',
                    'America/Chihuahua',
                    'America/Chihuahua',
                    'America/Mazatlan',
                    'US/Mountain',
                    'America/Managua',
                    'US/Central',

Why is it not finding SetTimezone from App\Http\Requests? I am looking at the folder structure and clearly I have a SetTimezone.php in the App/Http/Requests folder. Any help would be appreciated. Thanks!

17th February, 2017

clat23 left a reply on Form Request Validation, Class App\Http\Controllers\StoreBlogPost Does Not Exist • 1 month ago

I have the same problem and applied the solution of the best answer but I'm still getting the error:

ReflectionException in RouteSignatureParameters.php line 25: Class App\Http\Requests\SetTimezone does not exist

Here's my SettingsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use App\Ebay;
use App\Paypal;
use Carbon\Carbon;
use Camroncade\Timezone\Facades\Timezone;
use App\Http\Requests\SetTimezone;


class SettingsController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');

        // $this->middleware('subscribed');
    }

    public function show()
    {
        Auth::user()->updateTokenStatus();
        return view('settings', Auth::user());
    }

    public function setTimezone(SetTimezone $request)
    {
        $newTimezone = request()->timezone;
        Auth::user()->setTimezone($newTimezone);
        return redirect()->action([email protected]');
    }

and my SetTimezone.php that was created from "php artisan make:request SetTimezone"

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SetTimezone extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'timezone' => [
                'required',
                Rule::in([
                    'Pacific/Midway',
                    'Pacific/Samoa',
                    'Pacific/Honolulu',
                    'US/Alaska',
                    'America/Los_Angeles',
                    'America/Tijuana',
                    'US/Arizona',
                    'America/Chihuahua',
                    'America/Chihuahua',
                    'America/Mazatlan',
                    'US/Mountain',
                    'America/Managua',
                    'US/Central',
                    'America/Mexico_City',
                    'America/Mexico_City',
                    'America/Monterrey',
                    'Canada/Saskatchewan',
                    'America/Bogota',
                    'US/Eastern',
                    'US/East-Indiana',
                    'America/Lima',
                    'America/Bogota',
                    'Canada/Atlantic',
                    'America/Caracas',
                    'America/La_Paz',
                    'America/Santiago',
                    'Canada/Newfoundland',
                    'America/Sao_Paulo',
                    'America/Argentina/Buenos_Aires',
                    'America/Argentina/Buenos_Aires',
                    'America/Godthab',
                    'America/Noronha',
                    'Atlantic/Azores',
                    'Atlantic/Cape_Verde',
                    'Africa/Casablanca',
                    'Europe/London',
                    'Etc/Greenwich',
                    'Europe/Lisbon',
                    'Europe/London',
                    'Africa/Monrovia',
                    'UTC',
                    'Europe/Amsterdam',
                    'Europe/Belgrade',
                    'Europe/Berlin',
                    'Europe/Berlin',
                    'Europe/Bratislava',
                    'Europe/Brussels',
                    'Europe/Budapest',
                    'Europe/Copenhagen',
                    'Europe/Ljubljana',
                    'Europe/Madrid',
                    'Europe/Paris',
                    'Europe/Prague',
                    'Europe/Rome',
                    'Europe/Sarajevo',
                    'Europe/Skopje',
                    'Europe/Stockholm',
                    'Europe/Vienna',
                    'Europe/Warsaw',
                    'Africa/Lagos',
                    'Europe/Zagreb',
                    'Europe/Athens',
                    'Europe/Bucharest',
                    'Africa/Cairo',
                    'Africa/Harare',
                    'Europe/Helsinki',
                    'Europe/Istanbul',
                    'Asia/Jerusalem',
                    'Europe/Helsinki',
                    'Africa/Johannesburg',
                    'Europe/Riga',
                    'Europe/Sofia',
                    'Europe/Tallinn',
                    'Europe/Vilnius',
                    'Asia/Baghdad',
                    'Asia/Kuwait',
                    'Europe/Minsk',
                    'Africa/Nairobi',
                    'Asia/Riyadh',
                    'Europe/Volgograd',
                    'Asia/Tehran',
                    'Asia/Muscat',
                    'Asia/Baku',
                    'Europe/Moscow',
                    'Asia/Muscat',
                    'Europe/Moscow',
                    'Asia/Tbilisi',
                    'Asia/Yerevan',
                    'Asia/Kabul',
                    'Asia/Karachi',
                    'Asia/Karachi',
                    'Asia/Tashkent',
                    'Asia/Calcutta',
                    'Asia/Kolkata',
                    'Asia/Calcutta',
                    'Asia/Calcutta',
                    'Asia/Calcutta',
                    'Asia/Katmandu',
                    'Asia/Almaty',
                    'Asia/Dhaka',
                    'Asia/Dhaka',
                    'Asia/Yekaterinburg',
                    'Asia/Rangoon',
                    'Asia/Bangkok',
                    'Asia/Bangkok',
                    'Asia/Jakarta',
                    'Asia/Novosibirsk',
                    'Asia/Hong_Kong',
                    'Asia/Chongqing',
                    'Asia/Hong_Kong',
                    'Asia/Krasnoyarsk',
                    'Asia/Kuala_Lumpur',
                    'Australia/Perth',
                    'Asia/Singapore',
                    'Asia/Taipei',
                    'Asia/Ulan_Bator',
                    'Asia/Urumqi',
                    'Asia/Irkutsk',
                    'Asia/Tokyo',
                    'Asia/Tokyo',
                    'Asia/Seoul',
                    'Asia/Tokyo',
                    'Australia/Adelaide',
                    'Australia/Darwin',
                    'Australia/Brisbane',
                    'Australia/Canberra',
                    'Pacific/Guam',
                    'Australia/Hobart',
                    'Australia/Melbourne',
                    'Pacific/Port_Moresby',
                    'Australia/Sydney',
                    'Asia/Yakutsk',
                    'Asia/Vladivostok',
                    'Pacific/Auckland',
                    'Pacific/Fiji',
                    'Pacific/Kwajalein',
                    'Asia/Kamchatka',
                    'Asia/Magadan',
                    'Pacific/Fiji',
                    'Asia/Magadan',
                    'Asia/Magadan',
                    'Pacific/Auckland',
                    'Pacific/Tongatapu'
                ])
        ];
    }
}

3rd February, 2017

clat23 left a reply on Registration: "Something Went Wrong. Please Try Again Or Contact Customer Support." • 1 month ago

Ok so I added

Use Carbon\Carbon;

to SparkServiceProvider.php and it worked. Does the Spark Documentation need to be updated?

Does the Laravel Spark Framework need to be updated to have this on fresh install?

clat23 left a reply on Registration: "Something Went Wrong. Please Try Again Or Contact Customer Support." • 1 month ago

Here's the error thrown in larvel.log:

[2017-02-04 03:45:48] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Providers\Carbon' not found in /home/vagrant/Code/myapp/app/Providers/SparkServiceProvider.php:85

clat23 left a reply on Registration: "Something Went Wrong. Please Try Again Or Contact Customer Support." • 1 month ago

It's also worth noting that when I remove from SparkServiceProviders.php the following code;

Spark::createUsersWith(function ($request) {
          $user = Spark::user();
          $data = $request->all();
          $user->forceFill([
              'name' => $data['name'],
              'email' => $data['email'],
              'timezone' => $data['timezone'],
              'password' => bcrypt($data['password']),
              'last_read_announcements_at' => Carbon::now(),
              'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
          ])->save();
          return $user;
        });

No error on user registration. But the user does not receive the timezone in the user's table in the database.

clat23 started a new conversation Registration: "Something Went Wrong. Please Try Again Or Contact Customer Support." • 1 month ago

I have followed this documentation: https://spark.laravel.com/docs/3.0/adding-registration-fields

Here's my code:

register-common-form.blade.php:

    <!-- Timezone -->
    <?php require(app_path().'/Includes/timezones.php'); ?>
    <div class="form-group" :class="{'has-error': registerForm.errors.has('timezone')}">
        <label class="col-md-4 control-label">Timezone</label>

        <div class="col-md-6">
            <select class="form-control" name="timezone" v-model="registerForm.timezone">
            @foreach ($timezones as $formTimezone => $utc)
                <option value="{{ $formTimezone }}">{{ $utc }}</option>
            @endforeach
            </select>

            <span class="help-block" v-show="registerForm.errors.has('timezone')">
                @{{ registerForm.errors.get('timezone') }}
            </span>
        </div>
    </div>

app.js


/*
 |--------------------------------------------------------------------------
 | Laravel Spark Bootstrap
 |--------------------------------------------------------------------------
 |
 | First, we will load all of the "core" dependencies for Spark which are
 | libraries such as Vue and jQuery. This also loads the Spark helpers
 | for things such as HTTP calls, forms, and form validation errors.
 |
 | Next, we'll create the root Vue application for Spark. This will start
 | the entire application and attach it to the DOM. Of course, you may
 | customize this script as you desire and load your own components.
 |
 */

require('spark-bootstrap');

require('./components/bootstrap');

Spark.forms.register = {
    timezone: ''
};

var app = new Vue({
    mixins: [require('spark')]
});

SparkServiceProvider.php

<?php

namespace App\Providers;

use Laravel\Spark\Spark;
use Laravel\Spark\Providers\AppServiceProvider as ServiceProvider;

class SparkServiceProvider extends ServiceProvider
{
    /**
     * Your application and company details.
     *
     * @var array
     */
    protected $details = [
        'vendor' => 'Your Company',
        'product' => 'Your Product',
        'street' => 'PO Box 111',
        'location' => 'Your Town, NY 12345',
        'phone' => '555-555-5555',
    ];

    /**
     * The address where customer support e-mails should be sent.
     *
     * @var string
     */
    protected $sendSupportEmailsTo = null;

    /**
     * All of the application developer e-mail addresses.
     *
     * @var array
     */
    protected $developers = [
        //
    ];

    /**
     * Indicates if the application will expose an API.
     *
     * @var bool
     */
    protected $usesApi = true;

    /**
     * Finish configuring Spark for the application.
     *
     * @return void
     */
    public function booted()
    {
        Spark::useStripe()->noCardUpFront()->trialDays(10);

        Spark::freePlan()
            ->features([
                'First', 'Second', 'Third'
            ]);

        Spark::plan('Basic', 'myapp-test-1')
            ->price(10)
            ->features([
                'First', 'Second', 'Third'
            ]);

        Spark::validateUsersWith(function () {
            return [
                'name' => 'required|max:255',
                'email' => 'required|email|max:255|unique:users',
                'timezone' => 'required|max:50',
                'password' => 'required|confirmed|min:6',
                'vat_id' => 'max:50|vat_id',
                'terms' => 'required|accepted',
            ];
        });

        Spark::createUsersWith(function ($request) {
          $user = Spark::user();
          $data = $request->all();
          $user->forceFill([
              'name' => $data['name'],
              'email' => $data['email'],
              'timezone' => $data['timezone'],
              'password' => bcrypt($data['password']),
              'last_read_announcements_at' => Carbon::now(),
              'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
          ])->save();
          return $user;
        });
    }
}

I have added

$table->string('timezone')->nullable();

to my create_users_table migration

I have updated my Users.php model to add timezone:

    protected $fillable = [
        'name',
        'email',
        'timezone',
    ];

When I attempt to register a new user with my app, I get the following error: "Something went wrong. Please try again or contact customer support."

What did I miss?

clat23 left a reply on Should I Not Be Using Public Static Function In My Model? • 1 month ago

Point taken @patoui However, I am trying not to modify the user model. I am actually using Laravel Spark and when I attempted to add settings columns (i.e. user timezone) to the create_users_table migration, it broke the authentication process. The framework was throwing an error and was redirecting the user (me) to the registration page with an error something along the lines of "Something went wrong, contact the site administrator".

So my workaround was to break user settings off on its own model, controller and table which references the user's id on the user table.

So I guess now I have to decide whether to figure out why I am not able to add settings columns to the user table, or continue with settings as its own model, controller and table while avoiding public static functions. Any suggestions?

clat23 started a new conversation Should I Not Be Using Public Static Function In My Model? • 1 month ago

Here's my SettingsController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Setting;

class SettingsController extends Controller
{
    public function setTimezone ()
    {
        $newTimezone = request()->timezone;
        Setting::setTimezone($newTimezone);
    }
}

And here's my model Setting.php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;

class Setting extends Model
{
    protected $userSettings;

    public static function setTimezone ($newTimezone)
    {
        $userSettings = static::where('user_id',  Auth::user()->id)->first();
        $userSettings->timezone = $newTimezone;
        $userSettings->save();
    }
}

I set this up in this way based on Jeffrey Way's demonstration on Eloquent here: https://laracasts.com/series/laravel-from-scratch-2017/episodes/7

While this code works properly, I do recall that using static functions is not recommended. Should I be implementing this a different way?

31st January, 2017

clat23 left a reply on Pulling In Outside Providers (Camroncade - Timezone) • 1 month ago

Yes that worked. Thanks for your help @w1n78 !

clat23 left a reply on Pulling In Outside Providers (Camroncade - Timezone) • 1 month ago

Tried this:

$timezoneForm = (new \Camroncade\Timezone\Timezone)->selectForm($user->timezone, 'Set Time Zone', $formAttributes);

Got this:

ErrorException in f6fd7675b144e6b0466b63d9fb0082b5b039e7ca.php line 23: Undefined property: stdClass::$timezone (View: /home/vagrant/Code

A bit frustrating....any help appreciated. Thanks...

clat23 left a reply on Pulling In Outside Providers (Camroncade - Timezone) • 1 month ago

Ok, I have a little progress based on @w1n78 's recommendation. I noticed that the outside service provider is "Camroncade\Timezone\TimezoneServiceProvider::class,"

So I tried this instead:

$timezoneForm = \Camroncade\Timezone\Timezone::selectForm($user->timezone, 'Set Time Zone', $formAttributes);

And got this error instead:

ErrorException in f6fd7675b144e6b0466b63d9fb0082b5b039e7ca.php line 23: Non-static method Camroncade\Timezone\Timezone::selectForm() should not be called statically (View: /home/vagrant/Code

Any thoughts?

clat23 left a reply on Pulling In Outside Providers (Camroncade - Timezone) • 1 month ago

Thanks @w1n78, I tried your recommendation but here's the new error:

ErrorException in f6fd7675b144e6b0466b63d9fb0082b5b039e7ca.php line 23: Class 'Camroncade\Timezone' not found (View: /home/vagrant/Code

clat23 started a new conversation Pulling In Outside Providers (Camroncade - Timezone) • 1 month ago

I was using Laravel 5.3 and all was fine with what I was doing. I recently decided to use Spark so that I can have billing integrated with my app, but it broke an Autoloaded Service Provider. Note: I installed a fresh new install of Spark as I know Spark cannot be added to an existing app.

So let's start with the outside service provider: https://github.com/camroncade/timezone

Here's my code:

composer.json

"require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "laravel/cashier": "~7.0",
        "laravel/spark": "*@dev",
        "camroncade/timezone": "0.1"
    },

config/app.php

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,

        /*
         * Package Service Providers...
         */
        Laravel\Tinker\TinkerServiceProvider::class,

        /*
         * Application Service Providers...
         */
        Laravel\Spark\Providers\SparkServiceProvider::class,
        App\Providers\SparkServiceProvider::class,
        Laravel\Cashier\CashierServiceProvider::class,
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        /*
         * Outside Service Providers...
         */
        Camroncade\Timezone\TimezoneServiceProvider::class,

Of course I did run 'composer update' in the terminal and received this confirmation:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 1 update, 0 removals
  - Updating league/flysystem (1.0.33 => 1.0.34) Downloading: 100%
  - Installing camroncade/timezone (0.1) Downloading: 100%
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.

Here's my code that I'm trying to run that implements outside service provider:

$user = DB::table('users')->where('id', Auth::user()->id)->first();

$formAttributes = array('class' => 'form-control', 'name' => 'timezone');

$timezoneForm = Timezone::selectForm($user->timezone, 'Set Time Zone', $formAttributes);

echo $timezoneForm;

I receive this error when the code above is ran:

ErrorException in f6fd7675b144e6b0466b63d9fb0082b5b039e7ca.php line 22:
Undefined property: stdClass::$timezone (View: /home/vagrant/Code...

(error was truncated for privacy)

Please help!

23rd December, 2016

clat23 left a reply on Unexpected Write To Database • 3 months ago

Absolutely correct. I don't know how that changed from datetime to timestamp. Thanks for your assistance.

clat23 left a reply on Unintentional Write To Database • 3 months ago

You're right, no question there. Well my question: what's causing the database write to the "ebay_token_expiration" column in my "users" table? This column is unexpectedly updated with the current date and time when one of the three following things happens:

  1. User creates an account

  2. User selects a timezone from my settings.blade.php page

<form method="POST" action="/settings/setTimezone">
  1. User selects an eBay site
<form method="POST" action="/settings/setEbaySiteId">

21st December, 2016

clat23 started a new conversation Unintentional Write To Database • 3 months ago

I have a column in my database table "ebay_token_expiration" that is being updated with the current date and time whenever a form is submitted from my page.

Here's my code

settings.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">Settings</div>

                <div class="panel-body">
                    <?php
                        use Carbon\Carbon;
                     ?>
                  <h4>General</h4>
                  <h5><u><b>Time Zone</b></u></h5>
                      <form method="POST" action="/settings/setTimezone">
                          <div class="form-group">
                              <?php

                                  $user = DB::table('users')->where('id', Auth::user()->id)->first();

                                  // Attributes declared for the package used on the following line
                                  $formAttributes = array('class' => 'form-control', 'name' => 'timezone');

                                  // camroncade/timezone package can be referred to at https://github.com/camroncade/timezone
                                  $timezoneForm = Timezone::selectForm($user->timezone, 'Set Time Zone', $formAttributes);

                                  echo $timezoneForm;

                              ?>
                          </div>
                          <div class="form-group">
                              <button type="submit" class="btn btn-primary">Apply</button>
                          </div>
                      </form>
                  <hr>
                  <h4>eBay</h4>
                      <?php

                          // EBAY SETTINGS SECTION: Token
                          // Statements to determine if eBay Token is expired.
                          $now = Carbon::now();
                          $expiration = Carbon::createFromFormat('Y-m-d H:i:s', $user->ebay_token_expiration);
                          $expired = ($now->gt($expiration));

                          if ($user->timezone != null) {
                              // Retrieve eBay Token expiration date and convert to user's timezone in a readable format
                              $ebayTokenExpiration = Carbon::createFromTimestamp(date("U",strtotime(Timezone::convertFromUTC($user->ebay_token_expiration, $user->timezone))))->toDayDateTimeString();
                          }

                          if ($user->ebay_token_expiration == '0000-00-00 00:00:00') {

                              print "<h5><u><b>Authorize My App with eBay</b></u></h5>
                                    <p>In order to use My App, you must authorize it to act on your behalf on eBay.</p>
                                        <form action=\"/ebay/obtainSession\">
                                            <div class=\"form-group\">
                                                <button type=\"submit\" class=\"btn btn-primary\">Begin</button>
                                            </div>
                                        </form>";

                          } elseif ($expired == true) {

                              $ebayTokenExpiration = Carbon::createFromTimestamp(date("U",strtotime(Timezone::convertFromUTC($user->ebay_token_expiration, $user->timezone))))->toDayDateTimeString();

                              print "<h5><u><b>My App Access to eBay</b></u></h5>
                                    Status: Expired <br>
                                    <p>Expired: $ebayTokenExpiration</p>
                                        <form action=\"/ebay/obtainSession\">
                                            <div class=\"form-group\">
                                                <button type=\"submit\" class=\"btn btn-primary\">Re-authorize</button>
                                            </div>
                                        </form>";

                          } else {

                              if($user->timezone == null) {

                                  print "<h5><u><b>My App Access to eBay</b></u></h5>
                                        Status: Authorized <br>
                                        <p>Authorization Expires: <em>Select a time zone to see token expiration date</em></p>";

                              } else {

                                  print "<h5><u><b>My App Access to eBay</b></u></h5>
                                        Status: Authorized <br>
                                        <p>Authorization Expires: $ebayTokenExpiration</p>";

                              }

                          }

                       ?>
                  <h5><u><b>Site</b></u></h5>
                  <p>Choose the eBay site to use when listing items.  Currently, United States is the only eBay site supported.</p>
                  <form method="POST" action="/settings/setEbaySiteId">
                      <div class="form-group">
                          <select class='form-control' name='site_id'>
                             <option value='0' <?php if ($user->ebay_site_id == 0) {echo "selected";}?>>United States</option>
                             <option value='2' <?php if ($user->ebay_site_id == 2) {echo "selected";}?>>Canada</option>
                           </select>
                      </div>
                      <div class="form-group">
                         <button type="submit" class="btn btn-primary">Apply</button>
                      </div>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('phpinfo', function () {
    return view('phpinfo');
});

Route::get('test', function () {
    return view('test');
});

Route::get('/', function () {
    return view('welcome');
});

Route::auth();

Route::get('home', [email protected]');

Route::get('list', [email protected]');

Route::get('manage', [email protected]');

Route::get('process', [email protected]');

Route::get('settings', [email protected]');

Route::get('reports', [email protected]');

Route::get('/ebay/obtainSession', [email protected]');

Route::post('/ebay/getToken', [email protected]');

Route::get('/ebay/verifyToken', [email protected]');

Route::get('/ebay/selectCategory', [email protected]');

Route::post('/settings/setTimezone', [email protected]');

Route::post('/settings/setEbaySiteId', [email protected]');

Route::get('phpinfo', [email protected]');

SettingsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use DB;

use Auth;

class SettingsController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Set the time zone.
     *
     * @return \Illuminate\Http\Response
     */
    public function setTimezone()
    {
        $userTimezone = request()->timezone;

        DB::table('users')
            ->where('id', Auth::user()->id)
            ->update(['timezone' => $userTimezone]);

        return view('settings');
    }

    /**
     * Set the time ebay Site ID.
     *
     * @return \Illuminate\Http\Response
     */
    public function setEbaySiteId()
    {
        $ebaySiteId = request()->site_id;

        DB::table('users')
            ->where('id', Auth::user()->id)
            ->update(['ebay_site_id' => $ebaySiteId]);

        return view('settings');
    }

}

It is also worth noting that when the user first creates an account, "ebay_token_expiration" is also updated with the current date/time. Refreshing the settings.blade.php page does not update "ebay_token_expiration".

Please help! Thanks...

12th December, 2016

clat23 left a reply on "Unknown Database" From App, However No Problem With Migrations From The Command Line • 3 months ago

Thanks ZetecVan that did it! You were right, database was created on my local machine and not in my VM. I forgot, I SSH'd into Vagrant to migrate my tables before. Thanks again!

clat23 left a reply on "Unknown Database" From App, However No Problem With Migrations From The Command Line • 3 months ago

Thanks, I've switched to DB_HOST=localhost and DB_PORT=33060; same error "PDOException in Connector.php line 55: SQLSTATE[HY000] [1049] Unknown database 'clat23_database'

clat23 left a reply on "Unknown Database" From App, However No Problem With Migrations From The Command Line • 3 months ago

Thanks for the reply. I do have real values there. I removed it to protect my privacy. I have edited my post to make it clear.

clat23 started a new conversation "Unknown Database" From App, However No Problem With Migrations From The Command Line • 3 months ago

First off, I'm new to all this. I have never developed an app before. I had started last year and had a little bit of progress. I followed the tutorials here on Laracasts. I hit a road-block and stopped for several months. Somewhere in between my computer crashed, luckily I had my project folder saved on Dropbox.

I started up again this week with a fresh install of macOS, Homestead (via VirtualBox/Vargrant) composer, Laravel, MySQL server/workbench, etc. I edited the homestead.yaml file to point to my project's folder in Dropbox. When visited my app's URL (http://homestead.app) it loaded up just fine. I recreated the database and re-ran the migrations. All was well, my database schemas were just as they were when I was first working on this.

However, when I attempted to create a test user in my app, I received the following error: "PDOException in Connector.php line 55: SQLSTATE[HY000] [1049] Unknown database 'database_name_here"

The weird part is that the database migrations were successful when I ran "php artisan migrate".

What am I missing? Are there any special processes I need to perform to properly transition my project folder from my old install of my development environment to my new install?

Below you will find the code (that I believe) pertain to my issue, please let me know if any other part of my code will help diagnose this issue. Thanks!

.env:

APP_ENV=local APP_DEBUG=true APP_KEY=[app_key_here] APP_URL=http://localhost

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=[database_name_here] DB_USERNAME=[database_username_here] DB_PASSWORD=[password_here]

CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_DRIVER=log MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

database.php:

Edit Your Profile
Update

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