codemode

Experience

5,860

0 Best Reply Awards

  • Member Since 5 Months Ago
  • 47 Lessons Completed
  • 0 Favorites

17th June, 2017

codemode left a reply on Using A Url Slug And Id On The Route • 1 week ago

@topvillas - I understand. What i want to include is, the slug in the url.

codemode left a reply on Using A Url Slug And Id On The Route • 1 week ago

@topvillas - to avoid duplicate urls

codemode started a new conversation Using A Url Slug And Id On The Route • 1 week ago

Hello,

I'm trying to put the slug and id on the URL.

So, i have a Post model, with basic things like id, title, description. (example - 1 , first-title, first description)... and i want the URL to look like www.website.com/first-title_1

Route - ´´´Route::get('{slug}_{id}', [email protected]');´´´

Controller - ´´´public function show(Post $id, $slug) { return $id; //or compact into a view // and use str_slug() on the $title }´´´

I'm not sure if i need to store the slug into the database, also i'm not sure how the passing of values for $id and $slug should be.

Any help please? Thanks!

25th February, 2017

codemode left a reply on JWT Token Based Authentication • 4 months ago

Agh, i don't know how the "tymon/jwt-auth": "0.5.*" was not saved on my composer.json . All good now.

codemode started a new conversation JWT Token Based Authentication • 4 months ago

Hello, I'm trying to use Token based authentication from - https://github.com/tymondesigns/jwt-auth/

As in the installation instructions in - https://github.com/tymondesigns/jwt-auth/wiki/Installation

When i do - php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

i see - [Symfony\Component\Debug\Exception\FatalThrowableError] Class 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider' not found

Here is my 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,
        Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,
'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,
        'JWTAuth'   => Tymon\JWTAuth\Facades\JWTAuth::class,
        'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class

    ],

Your help is appreciated!

20th February, 2017

codemode left a reply on Basics Of Vue • 4 months ago

Got it, i was referring the root element on a div above the element. On providing the root id to the , it's all good.

codemode started a new conversation Basics Of Vue • 4 months ago

I'm on this tutorial https://laracasts.com/series/learn-vue-2-step-by-step/episodes/19

The view file -

 <input type="text" name="peso" class="form-control" v-model="peso" />
 <input type="text" name="altura" class="form-control" v-model="altura" />

Added CDN files before the ending body tag-

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    
 <script src="https:[email protected]/dist/vue.js"></script>
  
 <script src="/js/app.js"></script>

Content of app.js -

new Vue({
    
    el: '#result',
    
    data: {
      
    },
    
    methods: { 
        
    }
    
});

Note that i have not currently defined ´peso´ and ´altura´ in my data. Which should give errors on my console. I get none :| ..

Besides, i have installed the Vue DevTool extension on my chrome, and after i define the data fields like -

new Vue({
    
    el: '#result',
    
    data: {
      peso: '',
    altura: ''
    },
    
    methods: { 
        
    }
    
});

... i do not see the reactive values reflecting in my Vue DevTools. What am i missing? Thanks!

19th February, 2017

codemode left a reply on No Redirect After Form Submission • 4 months ago

@jlrdw If such little things get you, then you really need to calm your nerves a bit. Again, i'm not here to continue a silly conversation on personal decisions. You seem to be having a bad day today.. i wish you a better rest of the day.

codemode left a reply on No Redirect After Form Submission • 4 months ago

@jlrdw Dude, i have no idea why you'd blow your steam on something that others are doing. This bothers you so much? just avoid it.

codemode left a reply on No Redirect After Form Submission • 4 months ago

@jlrdw everyone has their reasons to what they are doing. Yes there are better ways of doing things with time, but again - People sometimes have their reasons. Do you want me to write about my personal life, and proceedings here? No.

If this troubles you, please avoid writing, rather than typing something negative.

codemode left a reply on No Redirect After Form Submission • 4 months ago

@amitshrestha221 Yes the form is working fine, and no, {{}} are not really required in the action if you're not passing any dynamic values to the url.

codemode left a reply on No Redirect After Form Submission • 4 months ago

Anyone who can help here :( .... i need to show this code to an institute. I'll really appreciate it.

codemode left a reply on No Redirect After Form Submission • 4 months ago

Hi @Snapey , thank you for your reply. Could you give me a simple example for this code (i'm still new to laravel) -

View -

<form method="POST" action="check-imc">
                        <div class="form-group">
                            <label for="peso">Peso (Kg) : </label>
                            <input type="text" name="peso" class="form-control"/>
                            <label for="altura">Altura (m) : </label>
                            <input type="text" name="altura" class="form-control"/>
                            <br />
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <input type="submit" value="Enviar" class="btn btn-primary pull-right"/>
                        </div>
                    </form>

Controller -

public function store(Request $request)
    {
        $imc = new Imc;
        $imc->peso = $request->peso;
        $imc->altura = $request->altura;
        $altura2 = ($imc->altura) * ($imc->altura);
        $imc->imccalculado = ( $imc->peso / $altura2 );
    
    $imc->save();
    
     }

So the value of $imc->imccalculado should be displayed on the view file without refreshing..

Thanks a lot!

codemode started a new conversation No Redirect After Form Submission • 4 months ago

Hello, I have a very simple form -

<form method="POST" action="check-imc">
                        <div class="form-group">
                            <label for="peso">Peso (Kg) : </label>
                            <input type="text" name="peso" class="form-control"/>
                            <label for="altura">Altura (m) : </label>
                            <input type="text" name="altura" class="form-control"/>
                            <br />
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <input type="submit" value="Enviar" class="btn btn-primary pull-right"/>
                        </div>
                    </form>

And i have a post route like - Route::post('check-imc', [email protected]')

In which there is store function, which stores the data.

I do not want to redirect/refresh after i click the submit button. Is that possible? Thanks!

codemode started a new conversation Fetching The Last Entry • 4 months ago

Hello,

I am trying to extract the last made entry by a particular user on my controller. This is what i currently have -

$all = Imc::where('user_id', Auth::id())->get();
$last = collect($all)->last();
 return $last;

Though this works, but i'm sure there is a better way to extract just that one last entry, rather than extracting all, and then refining the last.

Thanks!

18th February, 2017

codemode started a new conversation Pagination Error • 4 months ago

I'm trying to paginate my view, but i get this error - Call to undefined method Illuminate\Database\Query\Builder::links()

Controller function -

public function index()
    {
        
        $imc_obj = Imc::where('user_id', Auth::id())->paginate(5);
      
        return view('imc.index', compact('imc_obj'));
        
        
    }

View file -

@foreach ($imc_obj as $imcs)
                      <tr>
                        <td>{{ $imcs->name }}</td>
                        <td>{{ date('F d, Y', strtotime($imcs->created_at)) }}</td>
                        
                      </tr>
                        @endforeach
                    </tbody>
                  </table>
                  {{ $imcs->links() }}

codemode left a reply on Displaying Posts Just To The Owner Of The Post • 4 months ago

Got it.. thanks guys!

(ps, i have no idea where the accept answer button went)

codemode left a reply on Displaying Posts Just To The Owner Of The Post • 4 months ago

Thanks @tykus and @Cronix Meanwhile i was reading the documentation, and one of the ways was just -

$imc_obj = Imc::where('user_id', Auth::id())->get();

...in my index() function on the controller, as Cronix suggested. Sweet.

However, i just tested @tykus method, and that works too! Though i did not understand what is the imcs() in $imc_obj = Auth::user()->imcs()->get();

Let's break it down... Auth::user() gives the object of the current logged in user. Is imcs() an object of all imcs? Where is this value coming from?

Thanks!

codemode started a new conversation Displaying Posts Just To The Owner Of The Post • 4 months ago

Hi, I'm doing a small test in which users can fill in a form, and post some information. I'd like the users to be able to see only their own posted information, and not what others has posted.

Here is the route -

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

This triggers the index function on my controller which looks like -

public function index()
    {
        $imc_obj = Imc::all();

        return view('imc.index', compact('imc_obj'));
    }

And this returns the object on the view, which i iterate to display all results as -

 @foreach ($imc_obj as $imc)

$imc->text

@endforeach

How can i show only those posts to the person who has made specific posts? Many thanks!

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

Thanks @tykus and @futuremandigital .. you guys are awesome!

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

@tykus My brain hurts a bit lol. Yes, you're right... i should not pass a $task->id . My mistake.

If it's not too much to ask, can you tell me, when i create a new task, how will i be able to associate this to a logged in user?

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

@tykus No, sorry, i guess i did not explain well. I am trying to access form.blade.php

Just on accessing this file from my browser i get this error.. i can't even see the form yet.

And on this blade file i have a tag, whose action contains $task - which laravel is not able to identify.

All in all, i am trying to create a new task.

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

@tykus , still does not work.

PS - if i remove that variable and just do -

 <form method="POST" action="/store">

I get no error. I don't understand..

And if i comment the storeTask function, and even the "post" route, i still get the error. :(

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

Hi @tykus , for storeTask, i am doing -

public function storeTask(Request $request)

I just tried with $task too, but i get the same error :)

Any other ideas?

codemode left a reply on Basic Qs - Saving An Object To A User Related Table • 4 months ago

@Cronix Sorry, that was a type, i'll just update that. Any other ideas?

codemode started a new conversation Basic Qs - Saving An Object To A User Related Table • 4 months ago

Hello,

I have 2 tables, one is a standard User table (autogenerated by Auth), and another for tasks. So every user can have several tasks.

In the view, i have a file called "form,blade.php" which has a simple form to create a new task like -

 <form method="POST" action="/store/{{ $task->id }}">

And in the web routes, i have -

Route::post('store/{task}', [email protected]');

On going to localhost/form , i see an error - Undefined variable: task Which points to the .

Help please! Thanks

codemode started a new conversation Class Foo Extends Model - A Basic Doubt • 4 months ago

When you create a new model, for example - php artisan make:model foo

This creates a model file, with this structure -

class foo extends Model
{
    //
}

However, on the pre-generated user class, from the auth model, the user model is like this -

class User extends Authenticatable

I want to create a relationship, like a user can have may "foos". In the default setup, does this mean i need to extend "model" to my User class, besides extending "Authenticatable" ?

Many thanks

codemode left a reply on Php Artisan Migrate Returns Error • 4 months ago

@tomi ... just figured it out as you were typing the reply. Silly me.. hehe.

codemode started a new conversation Php Artisan Migrate Returns Error • 4 months ago

Hello, I just started a fresh Laravel project. This is what a new migration file looks like --

public function up()
    {
        Schema::create('imcs', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned->index();
            $table->decimal('peso');
            $table->decimal('altura');
            $table->decimal('imccalculado');
            $table->string('clasificacion');
            $table->timestamps();
        });
    }

However, on running php artisan migrate , i get --

 [Symfony\Component\Debug\Exception\FatalThrowableError]  
  Call to a member function index() on boolean             
                                                 

Where am i going wrong? Thanks

26th January, 2017

codemode left a reply on PHP Artisan Migrate Not Able To Identify New Migration • 5 months ago

..anyone?

25th January, 2017

codemode started a new conversation PHP Artisan Migrate Not Able To Identify New Migration • 5 months ago

Hello, I'm just testing Laravel 5.4 with a very basic app. I just created new migration, and for some reason when i do - php artisan migrate

i see this - [PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

It seems it cannot identify that i created a new migration. Any ideas? Thanks.

codemode left a reply on Route URL Vs View • 5 months ago

Understood, thanks!

codemode left a reply on Route URL Vs View • 5 months ago

Thanks @w1n78 . Does this mean i can :

Route::get('box', [email protected]); - in the route

public function index(){
return view('all-boxes');
}
```  - in the controller

.. and this will show in the URL http://website.com/box ... but for the content it will load all-boxes.blade.php . Did i get this right?

codemode started a new conversation Route URL Vs View • 5 months ago

Hi, I feel confused about the text we write in the routes file, and how we name the views. For example, what exactly is the "box" below?

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

Is it just a url, and it does not matter if /box location actually exists or not? Also, if i want to display a list of boxes, i'll be creating a view, and probably name it "all-boxes". How does the "all-boxes" (view) url differ from "box" (route) ?

Sorry if the question is silly, i'm new. Thanks!

14th January, 2017

codemode left a reply on BadMethodCallException Error From Laracasts • 5 months ago

..got it. All i had to do was - namespace App

codemode left a reply on BadMethodCallException Error From Laracasts • 5 months ago

... please can someone help. I can't find the solution on googling either

13th January, 2017

codemode left a reply on BadMethodCallException Error From Laracasts • 5 months ago

Now even if i do "$card = new Card;" i get -

PHP Fatal error: Class 'Card' not found in eval()'d code on line 1

This was working before. This is so frustrating, i'm losing my mind.

codemode left a reply on BadMethodCallException Error From Laracasts • 5 months ago

Hi @tykus_ikus , thank you for your reply. No. it does not have that method.. and if i remember correct, it was not mentioned in the tutorial. I'm not sure what needs to be added there :(

codemode started a new conversation BadMethodCallException Error From Laracasts • 5 months ago

Hi, Laravel newbie here.. Im doing this tutorial - https://laracasts.com/series/laravel-5-from-scratch/episodes/10 . At around 15:10, on doing $card->addNote($note); - Gives error - BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::addNote()' .

I followed everything as in the tutorial. Help please! Thanks.

codemode left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 218 • 5 months ago

..it was a typo :\ my bad.

Additionally, i got a "TokenMismatchException" .. whose solution was to add "" to my form (which i found on laracasts user comments) .

Is there a specific reason why this was not mentioned in the tutorial?

codemode started a new conversation MethodNotAllowedHttpException In RouteCollection.php Line 218 • 5 months ago

I'm following this tutorial - https://laracasts.com/series/laravel-5-from-scratch/episodes/9 . Here at around 11:00 we're supposed to create a new note... and after following everything as showed, and cross checking it for almost an hour i don't know WHY i'm getting "MethodNotAllowedHttpException in RouteCollection.php line 218" when i click the add note button. Please someone help.

12th January, 2017

codemode started a new conversation Connecting To Postgres • 5 months ago

Hi, Newbie here. I'm trying to connect a postgres DB to a fresh installation of laravel (on cloud9). I can't seem to run "php artisan migrate". It gives the following error -

[Illuminate\Database\QueryException] could not find driver (SQL: select * from information_schema.tables where table_schema = >public and table_name = migrations)

[PDOException] could not find driver

Pretty much everything is fresh/standard on my ubuntu system. This is my pgsql settings from database.php

'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', 'localhost'), > 'port' => env('DB_PORT', '5432'), 'database' => env('DB_DATABASE', 'Db-name'), 'username' => env('DB_USERNAME', 'ubuntu'), > 'password' => env('DB_PASSWORD', 'mypass'), > 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', 'sslmode' => 'prefer', ],

Any ideas?

Edit Your Profile
Update

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