jeudi 29 juin 2017

Laravel Seeding Issue

Guys.

I'm having an issue regarding Laravel's Seeding... so I'm getting a [ErrorException] Illegal offset type from One of My seeds. I believe my issue is coming from the foreign key, from the other table that I'm using

Below is My Model, My Table and My Seed which I'm getting.

Channel - Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Tenant;
use App\InactiveLead;
use App\Lead;


class Channel extends Model
{
    //
    protected $primaryKey = ['channel_id'];

    protected $fillable = ['name', 'tenant_name'];

    public function tenant()
    {
        return $this->belongsTo(Tenant::class, 'name', 'tenant_name');
    }

    public function inactivelead()
    {
        return $this->hasMany(InactiveLead::class, 'inactive_lead_id', 'inactive_lead_id');
    }

    public function lead()
    {
        return $this->hasMany(Lead::class, 'lead_id', 'lead_id');
    }
}

Channel - Table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateChannelsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('channels', function (Blueprint $table) {
            $table->increments('channel_id');

            $table->string('name');

            $table->string('tenant_name');
            $table->foreign('tenant_name')->references('name')->on('tenants');

            $table->unique(['tenant_name', 'name']);

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('channels');
    }
}

Channel - Seeder

<?php

use Illuminate\Database\Seeder;
use App\Tenant;
use App\Channel;
use Faker\Factory as Faker;

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

    $Tenants = Tenant::all()->pluck('name')->toArray();

    $Channels = array('SMS', 'Email', 'MMS', 'Call');

    $limit = 100;

    for($i = 0; $i < $limit; $i++) {
        $channel = new Channel([
            'tenant_name' => $faker->unique()->randomElement($Tenants),
            'name' => $faker->unique()->randomElement($Channels)
        ]);

        $channel->save();
    }
}
}



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

mercredi 28 juin 2017

i am not able to display my state name and city name using drop down in laravel

                This is my playingcards-advance ie view page

             <h5>Country:</h5>
                                      <select class="productcategory put" id="prod_cat_id">

                    <option value="0" disabled="true" selected="true">-Select-</option>
                    @foreach($prod as $cat)
                        <option value=""></option>
                    @endforeach

                </select>
                                      <h5>State:</h5>
                                    <select class="productname put">

                    <option value="0" disabled="true" selected="true">Select State</option>
                </select>
                 <h5>City:</h5>
                                         <select  class="city put">

                    <option value="0" disabled="true" selected="true">Select City</option>
                </select>

                <script src="http://ift.tt/2eBd7UN"></script>

                <script type="text/javascript">
                    $(document).ready(function(){

                        $(document).on('change','.productcategory',function(){
                            // console.log("hmm its change");

                            var cat_id=$(this).val();
                            // console.log(cat_id);
                            var div=$(this).parent();

                            var op=" ";

                            $.ajax({
                                type:'get',
                                url:'{!!URL::to('findProductName')!!}',
                                data:{'id':cat_id},
                                success:function(data){
                                    //console.log('success');

                                    //console.log(data);

                                    //console.log(data.length);
                                    op+='<option value="0" selected disabled>Select City</option>';
                                    for(var i=0;i<data.length;i++){
                                    op+='<option value="'+data[i].id+'">'+data[i].productname+'</option>';
                                   }

                                   div.find('.productname').html(" ");
                                   div.find('.productname').append(op);
                                },
                                error:function(){

                                }
                            });
                        });

                        $(document).on('change','.productname',function () {
                            var prod_id=$(this).val();

                            var a=$(this).parent();
                            console.log(prod_id);
                            var op="";
                            $.ajax({
                                type:'get',
                                url:'{!!URL::to('findcity')!!}',
                                data:{'id':prod_id},
                                dataType:'json',//return data will be json
                                success:function(data){
                                     console.log('success');

                                    console.log(data);
                              op+='<option value="0" selected disabled>choose city</option>';
                                    for(var i=0;i<data.length;i++){
                                    op+='<option value="'+data[i].id+'">'+data[i].city+'</option>';
                                   }

                 a.find('.city').html(" ");
                                   a.find('.city').append(op);





                                },
                                error:function(){

                                }
                            });


                        });

                    });
                </script>
  This is my Route code 
        Route::get('/playingcards-advance','PagesController@prodfunct');
        Route::get('/findProductName','PagesController@findProductName');
        Route::get('/findPrice','PagesController@findPrice');
        Route::get('/findcity','PagesController@findcity');




        This is PagesController code 
         public function prodfunct(){

                $prod=ProductCat::all();//get data from table
                return view('playingcards-advance',compact('prod'));//sent data to view

            }

            public function findProductName(Request $request){


                //if our chosen id and products table prod_cat_id col match the get first 100 data 

                //$request->id here is the id of our chosen option id
                $data=Product::select('productname','id')->where('prod_cat_id',$request->id)->take(100)->get();
                return response()->json($data);//then sent this data to ajax success
            }

           public function findcity(Request $request){


                //if our chosen id and products table prod_cat_id col match the get first 100 data 

                //$request->id here is the id of our chosen option id
                $q=City::select('city','id')->where('state_id',$request->id)->take(100)->get();
                return response()->json($q);//then sent this data to ajax success
            }



    The problem is that i m not able to display state and city but i m able to display country
    i have also made model of all table 
    why it is not displayng state and city in the code 
   when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)

    The problem is that i m not able to display state and city but i m able to display country
    i have also made model of all table 
    why it is not displayng state and city in the code 
   when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)

The problem is that i m not able to display state and city but i m able to display country i have also made model of all table why it is not displayng state and city in the code when i click on console and try to select country as America it is giving this error GET http://localhost/tmcards2/public/findProductName?id=1 500 (Internal Server Error)



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

How to manage Login/Logout in laravel using Auth

I have create one login module in laravel,what i have done yet is i have manually authenticated the user successfully and redirect on dashboard page but my issue is when user logged out from the application and again if they try to open that dashboard url then it is showing error MethodNotAllowedHttpException in RouteCollection at this time what i want is if user is not authenticated then it will directly redirect on our login page.I have also tried to put some logic in my LoginController Constructor but it is also not working.Below is my code with file path.

laravelproject\app\Http\routes.php

Route::auth();
Route::post('/login-submit', 'LoginController@loginSubmit');
Route::get('/log-out',[
    'uses'=>'LoginController@logOut',
    ]);

laravelproject\app\Http\Controllers\LoginController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;

//to take input from user
use App\Http\Requests;
use Illuminate\Http\Request;
//end

class LoginController extends Controller
{


    public function loginSubmit(Request $request)
    {

         $email=$request->email;
         $password=$request->password;

         //var_dump($credentials);die;
        if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
            // Authentication passed...

             return view('dashboard');
        }
        else
        {
             return view('auth/login');
        }    
    }

    public function logOut() {


        Auth::logout();

        return view('auth/login');

    }
}

Error after getting logout and trying to accessing dashboard url MethodNotAllowedHttpException in RouteCollection



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

eloquent relation not working on live server

I have two tables one is user and other is profile. one user can have one profile. This relation works perfectly on local server but when i upload it on live server the relations are not working not just user and profile but other relations also. here is my laravel model code for profile and user.

class Profile extends Model
{
  protected $fillable = ['user_id','fname','mname','lname',
    'birthdate','country','address','phone', 'image'];

  protected $hidden = ['user_id'];

  public $timestamps = false;

  public function users() {
    return $this->belongsTo('App\User', 'id');
  }
}

User model

class User extends Authenticatable
{
  protected $fillable = [
    'name', 'email', 'password', 'email_token'
  ];

  protected $hidden = [
    'password', 'remember_token', 'email_token'
  ];

  public function users(){
    return $this->hasOne('App\Profile', 'user_id');
  }
}

Here how i am trying to get profile data from login user in controller

Auth::user()->users->image



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

ReflectionException in Route.php Class Controller does not exist

I'm using Laravel 5.2 in a centos 5.8 server and getting the following error:

ReflectionException in Route.php line 280:
Class xxxx\Http\Controllers\CpanelController does not exist


ErrorException in ClassLoader.php line 412: include(/home/xxxx/vendor/composer/../../app/Http/Controllers/CpanelController.php): failed to open stream: Permission denied

Im trying with:

php artisan cache:clear

chmod -R 777 storage

composer dump-autoload

But the problem persists



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

Laravel Lumen Mail and Amazon SES 500 Internal Server Error on Ubuntu Server (Production)

Spent a good deal of time reviewing this...

What I've double, triple checked and against existing Stack Overflow current issues:

  • .env has all the correct creds.. all Amazon SES req.
  • Fixed/reviewed all Laravel Mail req.
  • Changed MAIL_DRIVER = log

Everything works fine on localhost.. perfect

Set everything up on Ubuntu, fails. If I comment out the Mail part, I get the response message that would come directly after the Mail lines of code.

I'm thinking whether it has anything to do with pointing to the public folder and then the route?

http://ift.tt/2t31oG8

Also, my domain is managed by AWS Route 53 and points to a Digital Ocean Ubuntu Server IP address.

Any ideas appreciated. Thank you!



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

Laravel 5 define app wide or global variable

So I am using Laravel 5 and Laravel Spark. I have a variable I want available to ALL views. What is the best method for this? The variable I need is the terms variable used in spark where it is parsing the terms.md file. I know that using a global variable is not the right answer, but i dont know how else to do it

I am using it in a modal, so I could load it via Vue.

Thanks



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