splendidkeen

Experience

2,420

0 Best Reply Awards

  • Member Since 2 Weeks Ago
  • 14 Lessons Completed
  • 0 Favorites

17th October, 2017

splendidkeen started a new conversation How To Store Content From A User's Profile Within Two Tables? • 1 day ago

Hello everybody, how are you?

I am currently working on a process, in which I am logged in as a User, and I can edit my profile. The changes will be stored within the 'users' table.

Users table migration:

public function up()
    {
        Schema :: create ('users', function(Blueprint $table){
            $table->increments('id');
            $table->string ('email'); 
            $table->string ('username');
            $table->string ('password');
            $table->string ('first_name')->nullable();
            $table->string ('last_name')->nullable();
            $table->string ('remember_token')->nullable();
            $table->timestamps();
    });

    }

Now I want to create another table, to store values for my profile such as 'Location' / or 'Street' or Pictures.

How do I have to connect my authenticated User to the second table, to store more content.

Any suggestions? Thank you.

splendidkeen left a reply on Upload Avatar: Route [$login] Not Defined Err • 1 day ago

@RamjithAp After pushing the Upload button it results in the Route [$login] not defined Err.

It is weird, because I can change other content within the same profile from my edit.blade.php view which has its own Controller.

Plus at the beginning it got an Err that it couldn't find the editavatar.blade.php Route, because I mentioned it within a Navigation on the view.

For this particular Route it got an Err:

(div class="col-sm-3")
    (a href="{{route('profile.editavatar')}}")(h4 class="headernav"  style="text-decoration: none;")Pictures & Avatar(/h4)(/a)
(/div)

editavatar.blade.php:


(form) enctype="multipart/form-data" action="/store" method="POST"(/)

    (label id="labeledit2") Update profile image(/label)
            
    (input) type="file" name="avatar"(/)
                
    (div) class="form-group"(/)
    (button type="submit" class="btn btn-default" style="margin-top: 20px; color: white;" id="button-profile")Update(/button)
    (/div)
    (input type="hidden" name="_token" value="{{ Session::token() }}")
        (/form)


splendidkeen left a reply on Relationship Between Two Models/Tables • 1 day ago

Thank you, I understand @Drfraker

The method for Users to follow brands, as the functionality behind a follow button. @tisuchi

splendidkeen left a reply on Data Distribution Within Database • 1 day ago

@lancecoder

Because it is unsigned? How to value?

splendidkeen left a reply on Upload Avatar: Route [$login] Not Defined Err • 1 day ago

This is my Sign in Route:

Route::get('/login', [
    'uses' => '\Modernoo\Http\Controllers\[email protected]', 
    'as' => 'auth.signin',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);

Route::post('/login', [
    'uses' => '\Modernoo\Http\Controllers\[email protected]',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);


16th October, 2017

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

I deleted and recreated the table migration again, now it spits this err @lancecoder

SQLSTATE[HY000]: General error: 1364 Field 'business_id' doesn't have a default value (SQL: insert into `businessadd` (`biography`, `sliderone`, `slidertwo`, `sliderthree`, `updated_at`, `created_at`) values (Hello, , , , 2017-10-16 18:11:58, 2017-10-16 18:11:58))

splendidkeen started a new conversation Upload Avatar: Route [$login] Not Defined Err • 2 days ago

As I wanted to upload a new avatar to my test user profile, I got back this error. I have changed nothing, and it worked before. Now this err comes up from nothing, when pushing the update button.

UploadController.php:

class UploadController extends Controller {

    public function index(){

        return view ('profile.editavatar');
    }

    public function store(Request $request){

        $this->validate($request, [
            'avatar' => 'max:600',

        ]);


        if($request->hasFile('avatar')){

            $user = Auth::user();

            $image   = $request->file('avatar');
            $filename = time() . '.' . $image->getClientOriginalExtension();
            $location = public_path('uploads/avatars/'. $filename);
            Image::make($image)->resize(300,300)->save($location);
            
            
            $user->avatar = $filename;
            $user->save();  
        }

        return view ('profile.editavatar');
        
    }

     public function getAvatar(){
        return $this->avatar;
    }


}

Route:

Route::get('/user/edit', [ 'uses' => '\App\Http\Controllers\[email protected]', 'as' => 'profile.editavatar', 'middleware' => ['auth'], ]);

Route::post('/store',[ 'uses' => '\App\Http\Controllers\[email protected]', 'middleware' => ['auth'], ]);

This is really weird. Maybe I am missing something? On my second system this process works without any problems. Thank you, guys.

splendidkeen started a new conversation Guard Protection Problem: Models & Routes • 2 days ago

Hello everybody, I am facing a major Logic problem within my Application regarding protected routes and my guards.

The process: Within my system I can log-in as a User, and as a Partner. Partners have their profiles as well as User. Therefore, I have a guard for every Model, which means that the profiles are protected by their guards. But I want my Users and Partners to be able to search each other after they are logged in.

Any suggestions?

Thank you so much!!

splendidkeen left a reply on SearchController To Parse Through Multiple Databases • 2 days ago

Ok, no problem & thank you for your help @Borisu

splendidkeen left a reply on SearchController To Parse Through Multiple Databases • 2 days ago

Ok, now I face a major problem. My business profiles are protected with the 'Partner' guard. When i know search a business within my user profile, or I do want to access a partner profile it spits the error Route [$login] not defined.because my route for the business profile is protected with the partner guard.

Any logic solution to this? @Borisu

splendidkeen left a reply on SearchController To Parse Through Multiple Databases • 2 days ago

Hey @Borisu , As I am currently trying to query two tables within my SearchController.php, it returns an error of unexpected return.

class SearchController extends Controller {

    public function getResults(Request $request){

        $query = $request->input('query'); 

        if(!$query){
            return redirect()->route('home');
        }

        $users = User::where(DB :: raw("CONCAT(first_name, ' ', last_name)"), 'LIKE', "%{$query}%")
        ->orWhere('username', 'LIKE', "%{$query}%")
        ->get();

        $business = Business::where(DB :: raw("CONCAT(company_name, ' ', zip)"), 'LIKE', "%{$query}%")
        ->orWhere('city', 'LIKE', "%{$query}%")
        ->get();

        $result = $users->merge($business)


        return view ('search.results')->with('users', $result); ??
    }
} 

Search.result view:


    (h3)Your search for "{{ Request::input('query')}}"(/h3)

    @if (!$users->count())
        (p)No results found, sorry.(/p)
    @else

    @if (!$business->count())
        (p)No results found, sorry.(/p)
    @else
    
    (div class="row")
        (div class="col-lg-12")

        @foreach ($users as $user)

            @include('user/partials/userblock')

        @endforeach

        @foreach ($business as $user)

            @include('partners/partials/partnerblock')

        @endforeach


    

Wouldn't it work like that?

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

I created everything twice. @matthew.erskine & it works, but I have a problem with grabbing the values from the second table for the authenticated user.

Edit2.blade.php:

(div) class="form-group{{ $errors->has('biography') ? ' has-error' : ''}}""(/)
    (label) for="biography" class="control-label" id="labeledit">Biography(/label)
    (input) type="text" name="biography" class="form-control" id="editfields" value="{{ Request::old('biography') ?: Auth::user()->biography }}"(/)
            @if ($errors->has('biography'))
                (span) class="help-block">{{ $errors->first('biography') }}(/span)
            @endif
                                        
(/div)  

It won't grab the value which is stored within the table 'businessadd'

Controller:

class PartnerSetupController extends Controller {

    public function getPartnerProfile($company_name){

        $business = Business::where('company_name', $company_name)->first();

        if(!$business){
            abort(404);
        }

        return view('partner.profile.index', compact('business'));
    }

    public function getPartnerEdit(){
        return view('partner.profile.edit2');  
    }
    
    public function postPartnerEdit(Request $request){
        
        $this->validate($request, [

            'biography' => 'max:140',
            'sliderone' => 'max:500',
            'slidertwo' => 'max:25',
            'sliderthree' => 'max:25',
            

            
        ]);
            
            $business_id = Auth()->user()->id;
            
            if(MoreBusiness::where('business_id', $business_id )->count()) {
                MoreBusiness::where('business_id',$business_id)->update([
                    'business_id' => $business_id,
                    'biography' => $request->input('biography'),
                    'sliderone' => $request->input('sliderone'),
                    'slidertwo' => $request->input('slidertwo'),
                    'sliderthree' => $request->input('sliderthree'),
                    ]);
            }
            

}

Migration:


public function up()
        {
            Schema :: create ('businessadd', function(Blueprint $table){
                $table->increments('id');
                $table->integer ('business_id')->unsigned(); 
                $table->string ('biography');
                $table->string ('sliderone');
                $table->string ('slidertwo');
                $table->string ('sliderthree');
                $table->timestamps();

                $table->foreign('business_id')
                    ->references('id')
                    ->on('business')
                    ->onDelete('cascade');
        });

      }

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

Can't see the bridge-problem @matthew.erskine

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

Ok i figured out the problem with the columns. So this works now, but when I change something within the first table, the content within the second turns into NULL.

What could that be @lancecoder

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

So I am editing my profile as a Business at the edit.blade.php view:

edit.blade.php:

// This is where I edit a value within my first table (works), but overwrites values within the second table to NULL

(div) class="form-group{{ $errors->has('first_name') ? ' has-error' : ''}}""
        (label) for="first_name" class="control-label" id="labeledit">Name(/label)
        (input) type="text" name="first_name" class="form-control" id="editfields" value="{{ Request::old('first_name') ?: Auth::user()->first_name }}"(/)
        @if ($errors->has('first_name'))
            (span) class="help-block">{{ $errors->first('first_name') }}(/span)
        @endif
                                        
(/div) 


// This is where I edit a value within my second table (works within DB), but not within my profile to show/grab the value


(div) class="form-group{{ $errors->has('biography') ? ' has-error' : ''}}""
        (label) for="biography" class="control-label" id="labeledit">Biography(/label)
        (input) type="text" name="biography" class="form-control" id="editfields" value="{{ Request::old('biography') ?: Auth::user()->biography }}"(/)
        @if ($errors->has('biography'))
            (span) class="help-block">{{ $errors->first('biography') }}(/span)
        @endif
                                        
(/div) 

Can't figure it out

splendidkeen left a reply on SearchController To Parse Through Multiple Databases • 2 days ago

Hey @Borisu / Thank you for the fast reply.

Where do I have to put the 'on' value?

Like so?


$users = User::where(DB :: raw("CONCAT(first_name, ' ', last_name)"), 'LIKE', "%{$query}%")
        ->orWhere('username', 'LIKE', "%{$query}%")
        ->get();

$business = Business:where(DB :: raw("CONCAT(company_name, ' ', location)"), 'LIKE', "%{$query}%")
        ->orWhere('xyz', 'LIKE', "%{$query}%")
        ->get();


Or another query on the db?

How would the merge look like?

splendidkeen started a new conversation SearchController To Parse Through Multiple Databases • 2 days ago

Hey everybody, As I am working with multiple Users & Models, I would like to extend my SearchController.php to parse through those Models/ Databases.

Process: My second database would be 'business' with values such as 'company_name' and the Business.php Model.

How can I combine the Controller to parse through both databases?

This is my SearchController.php

class SearchController extends Controller {

    public function getResults(Request $request){

        $query = $request->input('query'); 

        if(!$query){
            return redirect()->route('home');
        }

        $users = User::where(DB :: raw("CONCAT(first_name, ' ', last_name)"), 'LIKE', "%{$query}%")
        ->orWhere('username', 'LIKE', "%{$query}%")
        ->get();



        return view ('search.results')->with('users', $users);
}

Thank you.

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

Thank you for your patience @lancecoder

Yes, so that it won't create a new column for every change within my profile. Because the main idea was to distribute the data for a Business setup into two tables, that the first table mustn't carry all the data. For the second table, it would be great to also have a static column for with the business_id of my profile (that works already) and the changes within this column to be constant and always in this column (that doesn't work yet)

splendidkeen left a reply on Relationship Between Two Models/Tables • 2 days ago

Dear @tisuchi / Sorry for coming back again.

I tried some samples, but still can't obviously see the connection of two models within a method.

e.g.


public function users(){

    return  $this->belongsToMany('App\Models\User');
    
}

public function followBrand(Brand $brand){

    $this->users()->attach($user->id)

}

Would this process work or am I missing something?

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

@lancecoder

Maybe we can change something within the table?

public function up()
        {
            Schema :: create ('businessadd', function(Blueprint $table){
                $table->increments('id');
                $table->integer ('business_id')->unsigned(); 
                $table->string ('biography');
                $table->string ('sliderone');
                $table->string ('slidertwo');
                $table->string ('sliderthree');
                $table->timestamps();

                $table->foreign('business_id')
                    ->references('id')
                    ->on('business')
                    ->onDelete('cascade');
        });

      }

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

I used the code. But the second table will be overwritten if I edit something within the first table & if I change something within the second table for every change it creates another column with the correct business_id of the Auth::user(). Is their a possibility to have the columns static so that it won't create a new id of change for every change within the second table?

Because right now, if i change content for every change the id increments.

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

@lancecoder

So if I edit informations from the first table and save the changes within my app, the first table will be updated correctly and the second table 'businessadd' will be overwritten to null in every column + a new row will be created

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

@lancecoder / Now it saves the content correctly within the database, but always creates a new column with every change. Is it possibles to have a static column which changes the records in this very one?

Further, I can't show the content within my profile view? I mentioned it as the columns from my first table 'business' / when I mention something from my second table 'businessadd' it will not be displayed.

(div) class="form-group{{ $errors->has('biography') ? ' has-error' : ''}}""
        (label) for="biography" class="control-label" id="labeledit">Biography(/label)
        (input) type="text" name="biography" class="form-control" id="editfields" value="{{ Request::old('biography') ?: Auth::user()->biography }}"(/)
        @if ($errors->has('biography'))
            (span) class="help-block">{{ $errors->first('biography') }}(/span)
        @endif
                                        
(/div)  

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

@lancecoder / I already created MoreBusiness.php

class MoreBusiness extends Model implements AuthenticatableContract
{
    use Authenticatable;

    protected $guard = 'partner';
    
    protected $table = 'businessadd';
    
    
    protected $fillable = [
        
        'business_id', 
        'biography', 
        'sliderone',
        'slidertwo',
        'sliderthree',
    ];

     
    public function business()
    {
        return $this->belongsTo(Business::class, 'business_id');
    }


    public function getCompanyName(){
        return  $this->company_name;
    }
 
}

splendidkeen left a reply on Data Distribution Within Database • 2 days ago

Thank you @lancecoder

Now it spits the err:

Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically

15th October, 2017

splendidkeen left a reply on Relationship Between Two Models/Tables • 3 days ago

great. Thank you @tisuchi

splendidkeen started a new conversation Relationship Between Two Models/Tables • 3 days ago

Hello everybody,

I am planning a process integration within my project, that allows Users (User.php Model/ User table) to follow Brands (Brands.php Model/ Brands table). I already created a relationship between Users, where they can accept requests or add other Users as their friend. Now I just need a simple relationship between Users and Brands, where a User just follows or unfollows brands (Brands don't need to accept request or follow back).

My question is, how to connect two Models/Tables in a relationship where Users simply follow brands?

User.php: Example friendsOf() & addFriend Method

  public function friendOf(){
        return $this->belongsToMany('Modernoo\Models\User', 'friends', 'friend_id', 'user_id');
    }


 public function addFriend(User $user){
        $this->friendOf()->attach($user->id);
    }

FriendController.php for Follow functionality:

public function getAdding($username){
        
        $user = User::where('username', $username)->first();

        if (!$user){
            return redirect()
                ->route('home')
                ->with('info', 'That user could not be found.');
        }

        if(Auth::user()->id === $user->id){
            return redirect()->route('home');
        }

        Auth::user()->addFriend($user);

        return redirect()
            ->route('profile.index', ['username' => $username])
            ->with('info', 'Friend request sent.');
    }


How to connect two Models/Tables in a relationship where Users simply follow brands? Table 1: Users (id, username) Table 2: Brands (id, brand)

Thank you

splendidkeen left a reply on Data Distribution Within Database • 3 days ago

Hey @lancecoder / Sorry for my late reply.

This is my PartnerProfileController including the post Method / I think you called it Business Controller:

public function postPartnerEdit(Request $request){
        
        $this->validate($request, [

            'first_name' => 'alpha|max:50',
            'last_name' => 'alpha|max:50',
            'street' => 'max:25',
            'email' => 'max:25',
            'biography' => 'max:140',

            
        ]);


        Auth::user()->update([
            'first_name' => $request->input('first_name'),
            'last_name' => $request->input('last_name'),
            'street' => $request->input('street'),
            'email' => $request->input('email'),
            'biography' => $request->input('biography'),
        ]);

        


        return redirect()
            ->route('partner.profile.edit')
            ->with('info', 'Your profile has been updated.');
    }

I couldn't integrate the fourth step with the new Model & Table addition.

How could this be connected?

Thank you again.

12th October, 2017

splendidkeen left a reply on Data Distribution Within Database • 6 days ago

Thank you for your great effort @lancecoder / I will try it, and come back to you.

splendidkeen left a reply on Data Distribution Within Database • 6 days ago

Hey, @lancecoder Process: I am logged in as a business and can edit my account settings such as first_name or last_name within the Business table. Now I want to add more content for example a biography or header picture to my profile.

I would like to put this data into a newly created table. How can I connect this table or data to my profile/id within the table.

Let's call the second table: morebusiness

splendidkeen started a new conversation Data Distribution Within Database • 6 days ago

Hello everybody, how are you?

As I am expanding the configuration possibilities within my Business's Account setup, I would like to distribute the data within two data migrations/tables.

My first table: business

public function up()
    {
        Schema :: create ('business', function(Blueprint $table){
            $table->increments('id');
            $table->string ('email'); 
            $table->string ('company_name');
            $table->string ('password');
            $table->string ('zip');
            $table->string ('city');
            $table->string ('country');
            $table->string ('genre');
            $table->string ('street')->nullable();
            $table->string ('first_name')->nullable();
            $table->string ('last_name')->nullable();
            $table->string ('remember_token')->nullable();
            $table->timestamps();
    });

  }

How can I now create another migration/table, which will be fillable by the authenticated user from the business table?

Thank you

10th October, 2017

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

@kfirba Thank you again for solving my problem. You are great.

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

@kfirba Sorry for the misunderstanding. So what I am trying to do is, input content from the authenticated Business into the navigation, as we talked about earlier, which returns into null. I created a Business.php Model to control methods and more for my second system, meaning Users which access the app as Partners/Businesses.

Business.php

class Business extends Model implements AuthenticatableContract
{
    use Authenticatable;

    protected $guard = 'partner';
    
    protected $table = 'business';
    
    
    protected $fillable = [
        
        'email', 
        'company_name', 
        'password',
        'zip',
        'city',
        'country',
        'genre',
    ];

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


    public function getCompanyName(){
        return  $this->company_name;
    }
 
}

When I login with a Partner account I created, it works until I address methods within my navigation:

{{  Auth::user()->business->getCompanyName() }}

This is the navigation ()=<> :


(ul) class="nav navbar-nav navbar-right"
        @if (Auth::guard('partner')->check())
        (li)(a) {{  Auth::user()->business->getCompanyName() }}(/a)(/li)
        (li)(a) href="{{route('busauth.signout')}}"  id="navnav">Log out (/a)(/li)
        @else
                    
        @endif
(/ul)

It's weird, I can for example address

{{$business->getCompanyName() }}

within my main page, but within my navigation its spits an err with undefined variable business, again.

This is my User Model for the User Login:

User.php

class User extends Model implements AuthenticatableContract
{
    use Authenticatable;
    
    protected $table = 'users';
    
    
    protected $fillable = [

        'username', 
        'email', 
        'password',
        'first_name',
        'last_name',
        'location',
        'status',
        'avatar',
    ];

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

}

I am very thankful for your patience and help.

splendidkeen started a new conversation Multi Auth Basics/ Understanding Question • 1 week ago

Hello everybody, As I am facing some problems regarding multiple systems within my Laravel project, I would like to ask you some question with respect to the basics: on how to address the guards for example

Within Controller to specify guard:

public function __construct(){
    $this->middleware('auth:guard');
} 

Within route:

'middleware' => ['auth:guard'],

  • the Handler.php Setup / auth.php Setup and RedirecIfAuthenticated Setup

Am I right?

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

  • within my Handler.php file:
 protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        $guard = array_get($exception->guards(), 0);

        switch ($guard) {
            case 'partner':
                $login = 'busauth.signin';
                break;
            
            default:
                $login = 'auth.signin';
                break;
        }

        return redirect()->guest(route('$login'));
    }

Should be correct? Sorry again for the spam @kfirba

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

First, thank you again @kfirba. Where would one setup or address this relation? Maybe I forgot something over there?

Maybe within my BusinessAuthController at the sign-in method?

public function postSignin(Request $request){
        
        //Validate form data
        $this -> validate ($request, [
            'email' => 'required',
            'password' => 'required',
        ]);


        //Attempt to Log-in User
        //Auth::attempt($credentials, $remember);


        // if successful, then redirect to their intended location
        if(Auth::guard('partner')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)){
            
            return redirect()->route('partner.index');
        }
        // if unsuccessfull, then redirect back to the login with the form data
        return redirect()->back()->withInput($request->only('email', 'remember'))->with('info', 'Could not sign in with those details');
    }

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

Hey again @kfirba

Now my system fails with the err:

Call to a member function getCompanyName() on null

..when I address my method within the navigation:

{{ Auth::user()->business->getCompanyName() }}

Do I have to wrap the method within an Auth check or add middleware to this route, unless the user is authenticated? Btw, zhat is still on my 2nd system.

Sorry for the spam, but your help would be just great.

9th October, 2017

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

@kfirba

Maybe I made some mistake with my guards and providers?

Guard:

'partner' => [ 'driver' => 'session', 'provider' => 'business', ],

Provider:

'business' => [ 'driver' => 'eloquent', 'model' => App\Models\Business::class, ],

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

This results in:

Trying to get property of non-object 

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

Err: Method business does not exist.

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

Sorry, again @kfirba Why does this not work?

{{ Auth :: business()->getCompanyName() }}

splendidkeen left a reply on Undefined Method/Variable Problems On My 2nd System • 1 week ago

Thank you so much!

splendidkeen started a new conversation Undefined Method/Variable Problems On My 2nd System • 1 week ago

Hey everybody, I am not able to address methods I create within my models/controllers on my 2nd system.

For example: Business.php (Model)

 public function getCompanyName(){
        return  $this->company_name;
 }

Controller:

public function getPartnerProfile($company_name){

        $business = Business::where('company_name', $company_name)->first();

        if(!$business){
            abort(404);
        }

        return view('partner.profile.index')
            ->with('company_name', $business);
    }
}

Within view:

{{ $business->getCompanyName() }} 

Error:

Undefined variable: business

Just can't figure it out

7th October, 2017

splendidkeen started a new conversation Multi Auth Method Problem • 1 week ago

Hey, I face problems on my 2nd system. Can't see the problem.

Within the Business.php Model, I created this method:

public function getCompanyName(){ return $this->company_name; }

Info: Guard:

'partner' => [ 'driver' => 'session', 'provider' => 'business', ],

Provider:

'business' => [ 'driver' => 'eloquent', 'model' => App\Models\Business::class, ],

I want to refer within my navigation:

Spits error: Method business does not exist.

This is my Controller:

class PartnerProfileController extends Controller {

public function getPartnerProfile($company_name){

$business = Business::where('company_name', $company_name)->first();

if(!$business){
    abort(404);
}

return view('partner.profile.index')
    ->with('company_name', $business);
} }

Route is protected:

Route::get('/partner/{company_name}', [ 'uses' => '\App\Http\Controllers\[email protected]', 'as' => 'partner.profile.index', 'middleware' => ['auth:partner'], ]);

Any suggestions? Thank you.

splendidkeen left a reply on Auth Problem: Method Error • 1 week ago

Hey,

Within the Business.php Model, I created this method: public function getCompanyName(){ return $this->company_name; }

Info: Guard:

'partner' => [ 'driver' => 'session', 'provider' => 'business', ],

Provider:

'business' => [ 'driver' => 'eloquent', 'model' => App\Models\Business::class, ],

I want to refer within my navigation:

<ul class="nav navbar-nav navbar-right"> (Auth::guard('partner')->check())

<li><a href="{{ route('partner.profile.index', ['company_name' => Auth::business()->company_name]) }}" id="navnav">{{ Auth::business()->getCompanyName() }} </a></li>

</ul>

Spits error: Method business does not exist.

This is my Controller: class PartnerProfileController extends Controller {

public function getPartnerProfile($company_name){

$business = Business::where('company_name', $company_name)->first();

if(!$business){
    abort(404);
}

return view('partner.profile.index')
    ->with('company_name', $business);
} }

Route is protected:

Route::get('/partner/{company_name}', [ 'uses' => '\App\Http\Controllers\[email protected]', 'as' => 'partner.profile.index', 'middleware' => ['auth:partner'], ]);

Any suggestions? Thank you.

6th October, 2017

splendidkeen started a new conversation Auth Problem: Method Fail In 2nd System • 1 week ago

Info: Guard: 'partner' => [ 'driver' => 'session', 'provider' => 'business', ],

Provider: 'business' => [ 'driver' => 'eloquent', 'model' => App\Models\Business::class, ],

Within the Business.php Model, I created this method: public function getCompanyName(){ return $this->company_name; }

I want to refer within my navigation:

ul. class="nav navbar-nav navbar-right"> (Auth::guard('partner')->check())

li.a href="{{ route('partner.profile.index', ['company_name' => Auth::business()->company_name]) }}" id="navnav">{{ Auth::business()->getCompanyName() }} a.li

.ul

Spits error: Method business does not exist.

This is my Controller: class PartnerProfileController extends Controller {

public function getPartnerProfile($company_name){

$business = Business::where('company_name', $company_name)->first();

if(!$business){
    abort(404);
}

return view('partner.profile.index')
    ->with('company_name', $business);

} }

Route is protected:

Route::get('/partner/{company_name}', [ 'uses' => '\App\Http\Controllers\[email protected]', 'as' => 'partner.profile.index', 'middleware' => ['auth:partner'], ]);

Any suggestions? Thank you.

5th October, 2017

splendidkeen started a new conversation MultiAuth-Problem: Second System Doesn't Recognize Methods • 1 week ago

Info: Guard: 'partner' => [ 'driver' => 'session', 'provider' => 'business', ],

Provider: 'business' => [ 'driver' => 'eloquent', 'model' => App\Models\Business::class, ],

Within the Business.php Model, I created this method: public function getCompanyName(){ return $this->company_name; }

I want to refer within my navigation:

Spits error: Method business does not exist.

This is my Controller: class PartnerProfileController extends Controller {

public function getPartnerProfile($company_name){

    $business = Business::where('company_name', $company_name)->first();

    if(!$business){
        abort(404);
    }

    return view('partner.profile.index')
        ->with('company_name', $business);
}

}

Route is protected:

Route::get('/partner/{company_name}', [ 'uses' => '\App\Http\Controllers\[email protected]', 'as' => 'partner.profile.index', 'middleware' => ['auth:partner'], ]);

Any suggestions? Thank you.

2nd October, 2017

splendidkeen left a reply on Avatar Upload / Error: Image Will Be Stored, But Not Referenced Within DB {Creating Default Object From Empty Value}? • 2 weeks ago

Wow, you just solved my problem which I faced for nearly a month. Thank you

splendidkeen started a new conversation Avatar Upload / Error: Image Will Be Stored, But Not Referenced Within DB {Creating Default Object From Empty Value}? • 2 weeks ago

public function index(){

    return view ('profile.editavatar');
}

public function store(Request $request){

    $this->validate($request, [
        'avatar' => 'max:255',

    ]);

    Auth::user()->update([
        'avatar' => $request->input('avatar'),
    ]);

    if($request->hasFile('avatar')){

        $user = Auth::user();

        $image   = $request->file('avatar');
        $filename = time() . '.' . $image->getClientOriginalExtension();
        // $path     = storage_path('/uploads/avatars/'. $user->username . $filename );
        // Storage::makeDirectory($path, 0777, true);
        $location = public_path('uploads/avatars/'. $filename);
        Image::make($image)->resize(300,300)->save($location);
        
        
        $user->avatar = $filename;  
    }


    
}

There is some struggle with the $user variable, as I am editing the profile content with 2 Controllers. On for written content within the profile & one for Avatar Upload. This is the UploadController.

Any suggestions?

splendidkeen left a reply on Avatar Upload / Store Fail • 2 weeks ago

Also tried this with the Intervention Package. But it still doesn't stores the image anywhere but in the DB.

By the way, this is my route:

Route::post('profile.edit', [ 'uses' => '\Modernoo\Http\Controllers\[email protected]', 'middleware' => ['auth'], ]);

splendidkeen left a reply on Avatar Upload / Store Fail • 2 weeks ago

$image = $request->file('avatar'); $filename = time() . '.' . $image->getClientOriginalExtension(); // $path = storage_path('/uploads/avatars/'. $user->username . $filename ); // Storage::makeDirectory($path, 0777, true); $location = public_path('uploads/avatars/' . $filename); Image::make($image)->resize(300,300)->save($location);

$user->avatar = $filename;

Edit Your Profile
Update

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