samedi 24 juin 2017

Laravel Seeding error SQLSTATE[23000]

When I'm trying to seed my database, but I get an error saying that I have a duplicate entry '1' for the key 'users_class_id_unique.

Does anyone know what is causing this problem?

This is what the error looks like

[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' 
for key 'users_class_id_unique' (SQL: insert into `users` (`name`, 
`lastname`, `email`, `class_id`, `password`
`role_id`, `created_at`, `updated_at`) values (Example, Name, 
example@outlook.com, 1, 
$2y$10$gqFXkYt9LRoCH6LqsosEPOI/2t.VDoNzBgV3x/przh.1KiuJqvRwe, 2, 1971-06-20 
06:10:44, 1975-03-0
9 17:46:23))



[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' 
for key 'users_class_id_unique'

This is my seeder file

<?php

use Faker\Factory;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class UsersTableSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    $faker = Faker\Factory::create();

    //Zeker weten dat de eerste user één admin is
    DB::table('users')->insert([
        'name' => 'Rainier',
        'lastname' => 'Laan',
        'email' => 'rainier.laan@home.nl',
        'class_id' => 1,
        'password' => bcrypt('welkom'),
        'role_id' => 2,
        'created_at' => $faker->dateTime,
        'updated_at' => $faker->dateTime,
    ]);

    DB::table('users')->insert([
        'name' => 'Collin',
        'lastname' => 'Nieuw Beerta',
        'email' => 'collinweetnietwelkeemail@hotmail.com',
        'class_id' => 1,
        'password' => bcrypt('welkom'),
        'role_id' => 1,
        'created_at' => $faker->dateTime,
        'updated_at' => $faker->dateTime,
    ]);

    DB::table('users')->insert([
        'name' => 'Godpieter',
        'lastname' => 'alwin',
        'email' => 'Godpieter@Allmightygodpieter.com',
        'class_id' => 1,
        'password' => bcrypt('welkom'),
        'role_id' => 2,
        'created_at' => $faker->dateTime,
        'updated_at' => $faker->dateTime,
    ]);

    // Onderste code maakt 8 random users aan met het wachtwoord 'Welkom'

    foreach(range(1,7) as $index) {
        DB::table('users')->insert([
            'name' => $faker->name,
            'lastname' => $faker->lastName,
            'email' => $faker->email,
            'class_id' => rand(1, 3),
            'password' => bcrypt('welkom'),
            'role_id' => 1,
            'created_at' => $faker->dateTime,
            'updated_at' => $faker->dateTime,
        ]);
    }
}
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t3jVV3
via IFTTT

How to load css and js file in laraval

I am new in laraval and i want to include css and js from public folder 
using this 

But it is not working for me . public folder contains the assets folder in which i have css and js files  with is code

h1{
    color:darkgreen;
}

I want just css and js files  include in blade files . So i have created one folder inside public folder and include using this code 

But i am not able see effect of this css and js in blade file so please help me for include css and js file in blade file



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2t6uGpU
via IFTTT

Laravel: How can we know the error when sending HTTP request

I am trying to use a Http method to reactivate user's subscription, using HTTP request, but there might be two problems that exist (the json code would return two potential errors):

  1. Reactivating a canceled subscription with an invalid payment profile

    • Given you have a canceled subscription with ID "1000"
    • The subscription has an invalid payment profile Send a PUT request to http://ift.tt/2s2TQ9k
    • The response status should be "422 Unprocessable Entity"

The subscription should be canceled with the following response

  {
      "errors": ["The credit card on file could not be charged."]
  }

  1. Attempting to reactivate an already active subscription
    • Given you have an active subscription with ID "1000"
    • Send a PUT request to http://ift.tt/2s2TQ9k
    • The response status should be "422 Unprocessable Entity"

The subscription should be active with the following JSON response

  {
      "errors": ["Cannot reactivate a subscription that is not marked 
                    \"Canceled\", \"Unpaid\", or \"Trial Ended\"."]
  }

I am new to Laravel, therefore I would like to know the way I can detect the error when sending the request to the server, but right now I only have one option (without a valid if statement) which cannot detect the problem.

The function is here:

public function reactivateSubscription(Request $request)
{
    $chargify = new \Crucial\Service\Chargify ([
        'hostname' => env('CHARGIFY_HOSTNAME'),
        'api_key' => env('CHARGIFY_KEY'),
        'shared_key' => env('CHARGIFY_SHARED_KEY')
    ]);

    $subscription = $chargify->subscription();
    $user = $request->user();

    // we used Chargify Laravel SDK here
    $subscriptionId = $user->subscription->subscription_id;
    $subscriptionReact = $chargify->subscription()
        ->reactivate($subscriptionId);

    // we use Eloquent to let customers see the effect first
    $user->subscription->state = 'active';
    $user->subscription->save();

    return redirect('account/settings')
        ->with('account', [['msg' => 'Thanks, ' . $user->first_name . ',
         you are now subscribed!', 'type' => 'success', 'icon' => 'fa-check']]);
}

I think an if statement would do but I'm not sure how. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sNcOhp
via IFTTT

how to develop javascript event handle in laravel form

I need develop form with input text box, radio buttons and optional values in My laravel app. this is My simple form

<html>
<head>
<title>Form Generation</title>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br><br>

<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>

<br><br>

<select name="cars">
    <option value="volvo">Volvo XC90</option>
    <option value="saab">Saab 95</option>
    <option value="mercedes">Mercedes SLK</option>
    <option value="audi">Audi TT</option>
  </select>

<br><br>

<input type="submit">
</form>


</body>
</head>
</html> 

I need initial show only input box in My page

Name: <input type="text" name="name"><br><br> 

and then when cursor select to the input box and enter some values I need show (load) other items of the form

<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>

<br><br>

<select name="cars">
    <option value="volvo">Volvo XC90</option>
    <option value="saab">Saab 95</option>
    <option value="mercedes">Mercedes SLK</option>
    <option value="audi">Audi TT</option>
  </select>

<br><br>

<input type="submit">
</form>

how can I do this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u0ql4l
via IFTTT

PHP- Carbon Datetime DiffInSeconds and How to Group By Hour

I'm calculating difference between 2 datetimes in seconds but I want to group them by hours. It should be like that.

This is how I'm getting difference between 2 dates.

$date_diff = $first->created_at->diffInSeconds($second->created_at);

And For example first time is 09:47:20 and next one is 11:47:50 I need the group them by hour like this.

In 09:00 =  13.40 Minutes
In 10:00 =  60.00 Minutes
In 11:00 =  47.50 Minutes

How can I do that ? And what you'll suggest for this ?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tFtLdv
via IFTTT

Laravel 5 - Output valid XML

I'm using this http://ift.tt/1JawdLr to output XML, but it's not actually valid XML output.

$xml = DB::table("news")->select(['id', 'title', 'content', 'date_posted', 'author'])->orderBy("date_posted", "asc")->get();
        $formatter = Formatter::make($xml, Formatter::XML);
        $output   = $formatter->toXml();

        return response($output, 200)
            ->header('Content-Type', 'text/xml');

So how can I output valid XML in Laravel 5?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2s1Vkk2
via IFTTT

Laravel catch all route as last possible route

I am wanting to have a catch all route for catching any page that's isn't loaded. I have tried a couple of ways.

First way - I have created a seperate Service Provider and loaded it last in the config.

Second attempt was to intercept 404's

render method in Handler.php

if($exception instanceof NotFoundHttpException)
    return PageController::handleMissingPage();

Then the handleMissingPage() method

$slug = '/';

if(strlen($path) > 1)
    $slug = ltrim($path, '/');

if ($page = Page::->where('path', $slug)->first())
    return response()
        ->view($page->template, ['pageBuilder' => $page], 200);

abort(404);

This second way works, but it doesn't feel correct intercepting 404's. The user is also never seen as logged in doing it this way

I'm stuck as to what to try next, I assumed loading it in last would give it last priority



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sMQ0Ow
via IFTTT