Tetravalence

Experience

2,520

0 Best Reply Awards

  • Member Since 7 Months Ago
  • 17 Lessons Completed
  • 0 Favorites

27th August, 2018

Tetravalence left a reply on One-to-One Relationships • 1 month ago

@cmdobueno : It works fine. Thank you.

@abi : thank you for the explanation of how the collections work.

Tetravalence left a reply on One-to-One Relationships • 1 month ago

@jlrdw : the simplest queries are OK but chaining queries are not working.

@abi : your chaining query Post::find(1)->details is OK but this one

$collection = $posts->details()->where('post_protected', 'yes')->get();

returns an empty array. The Controller's code is

public function index()
{
   // GET /posts

  $post = new Post;

  $collection = $post->details()->where('post_protected', 'yes')->get();
  dd($collection);
  
  return ...
}      

Then I'm using this when Eloquent's method calls the hasOne method and returns its result.

Tetravalence left a reply on One-to-One Relationships • 1 month ago

@Abi: OK but any query returns an empty collection.

Tetravalence left a reply on One-to-One Relationships • 1 month ago

@jlrdw: I'm reading just now the Eloquent doc. Any suggestion is appreciated to solve my problem.

Tetravalence started a new conversation One-to-One Relationships • 1 month ago

Hello! I'm confused by the whole thing. According to the Eloquent documentation to define the relationship, we place a link method on the Eloquent model but I have troubles getting the formula to get any data. My Post Model is associated with one PostDetail. The relationship one-to-one is defined by the details method in Post

public function details()
{
    return $this->hasOne('Tetravalence\MyPackage\PostDetail', 'post_id');
}

This is the Post migration schema

        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('post_uid', false, true)->default(0);
            $table->text('post_title');
            $table->char('post_type', 20)->default('article');
            $table->char('post_status', 20)->default('draft');
            $table->foreign('post_uid')->references('id')->on('users');
        });

This is the PostDetail migration schema

        Schema::create('post_details', function (Blueprint $table) {
            $table->bigIncrements('post_details_id');
            $table->bigInteger('post_id', false, true);
            $table->longText('post_body');
            $table->char('post_discuss_status', 20);
            $table->timestamp('post_date')->nullable();
            $table->timestamp('post_last_update')->nullable();
            $table->text('post_excerpt');
            $table->char('post_protected', 255);
            $table->bigInteger('post_parent');
            $table->char('post_slug', 255);
            $table->char('post_metakeys', 255);
            $table->foreign('post_id')->references('id')->on('posts');
        });

My query is not working bacause I get an array(0)

        $collection = $posts->details()->where('post_protected', 'yes')->get();

        dd($collection);

What is the correct query to use?

25th August, 2018

Tetravalence left a reply on Problem With Indentation In Blade Views • 1 month ago

@Cronix , @crnkovic : I have to accept the inevitable. Thank you for the your replies!

Tetravalence left a reply on Problem With Indentation In Blade Views • 1 month ago

@crnkovic : Laravel 5.4 From Scratch, episode 11, time 12:15

Tetravalence left a reply on Problem With Indentation In Blade Views • 1 month ago

@crnkovic : OK so I should not take care of it but how do Laracasts tutorials come with HTML well indented? They also use ATOM.

Tetravalence left a reply on Problem With Indentation In Blade Views • 1 month ago

@crnkovic , @topvillas : Customers do also look at this. Watching video tutorials on Laracasts I have noticed that HTML source code is well indented so the question has arisen spontaneously.

Tetravalence started a new conversation Problem With Indentation In Blade Views • 1 month ago

Hi! I'm using Atom as IDE for developing Laravel projects but I haven't been able to figure as indentation works out yet. My HTML source code is practically a mess.

Messed Indentation

I have noticed this problem when I use Blade directives as include and extends. How do I fix the indentation?

14th August, 2018

Tetravalence started a new conversation ErrorException Using Readlink() • 2 months ago

Hello, I have an ErrorException that I'd like to handle when readlink() returns false.

public static function validateLink()
{
        $public_resources = public_path().
            '/vendor/'.static::getVendor().'/assets';

        return readlink($public_resources) ?
            $public_resources : false;
}

The failure is an expected behavior so I need the script continues to run after ternary operator.

12th August, 2018

Tetravalence left a reply on How To Use Auth Middleware In My Own Package • 2 months ago

@iambaz You did resolve my problem. Thank you.

Does anyone know why this code below is not working?

Route::middleware('web', 'auth', 'dashboard')->group(function () {
    Route::get('/dashboard', '[email protected]');
    Route::get('/dashboard/template', '[email protected]')->name('template');
});

While this one is correct

Route::group(['middleware' => ['web', 'auth', 'dashboard']], function () {
  Route::get('/dashboard', '[email protected]');
  Route::get('/dashboard/template', '[email protected]')->name('template');
});

Tetravalence left a reply on Problem With Auth Middleware • 2 months ago

@crnkovic the Auth middleware does a redirect back to the /home whenever I try to access the /got route even though I'm logged in. The code works fine if added to the main application route routes/web.php but it does not work if added to the package route vendor/tetravalence/mypackage/routes/web.php.

Tetravalence started a new conversation Problem With Auth Middleware • 2 months ago

Hi! The following snippet of code taken from a tutorial by Auth0.com

Route::get('/got', [
  'middleware' => ['auth'],
  'uses' => function () {
   echo "You are allowed to view this page!";
}]);

What is that supposed to do? When I log out and I try to access that route, Auth middleware redirected back to the/login route, same thing happens when I log in, the echo message is not displayed. Why?

11th August, 2018

Tetravalence left a reply on Assign A Key To Middleware In Package Development • 2 months ago

@tykus OK. Thank you!

10th August, 2018

Tetravalence started a new conversation Assign A Key To Middleware In Package Development • 2 months ago

Hello, I'd like to share Middlewares across a group of routes without needing to use their FQN. I know it's possible to assign the Middleware a key in app/Http/Kernel.php but I'm looking for a solution in package development that does not require to change the aforementioned file. Right now I'm using the MyPackageDashboard Middleware by means of his FQN

Route::middleware('auth', Tetravalence\MyPackage\Http\Middleware\MyPackageDashboard::class)->group(function () {
...
// group of routes
}

Where can I set up these keys in package development?

8th August, 2018

Tetravalence left a reply on Implement Mutiple Themes In A Laravel CMS • 2 months ago

@Aleem raised the problem I'm facing with package development. Does anyone know if I have to use a Middleware class to filter any asset used in the active theme? For exemple if current theme does use assets from this directory

/vendor/tetravalence/package/template/current/public/assets/css/style.css

the Middleware should copy style.css into public but I'm not sure if this task can be accomplished in an efficient way. I would be grateful for any advice you can give me.

6th August, 2018

Tetravalence left a reply on Subtitles Or Scripts For Lectures... • 2 months ago

@bobbybouwmann Edx videos go through automatic speech recognition to produce caption and transcript. They use external service from Cielo24 or 3 Play Media.

29th July, 2018

Tetravalence left a reply on Subtitles For Tutorials • 2 months ago

Any update? I have some difficulty with English listening. Thanks in advance

Tetravalence left a reply on Best Way To Set-up A Package Via Web? • 2 months ago

OK this question has been satisfactorily solved using a Service Provider and a global Middleware.

28th July, 2018

Tetravalence left a reply on Best Way To Set-up A Package Via Web? • 2 months ago

@cmdobueno OK, I find your idea really interesting but how should I implement it? Here is my test procedure which is not working, however:

  1. In Mypackage Service Provider I use the app array to inject the middleware into the Kernel in the similar way as it is done in Debug Bar service provider using pushMiddleware method.
  2. The middleware extends CheckForMaintenanceMode class.
  3. The Web route file has the following entry
Route::get('/maintenance', '[email protected]`);

Unfortunatly, the application continues to load the 503 default view bypassing my middleware.

26th July, 2018

Tetravalence started a new conversation Best Way To Set-up A Package Via Web? • 2 months ago

Hi, my package needs some records in the tables to work, for example the name of default theme, the e-mail of the site owner, etc. What's the best approach to this? I use a conditional statement in the route file together to a Controller that runs some routine, for example in routes/web.php

if (!file_exists(config_path().'/myapp.php')) {
    Route::get('/', '[email protected]');
} else {
   Route::get('/', '[email protected]');
}

So, if myapp.php file does not exist in config directory then MyApp runs the installer. The alternative is to use artisan vendor:publish from command line. Is this the correct way to proceed?

25th July, 2018

Tetravalence left a reply on Eloquent Model's Created_at And Updated_at Do Not Work • 2 months ago

@36864 : OK I've got it. Thank you!

Tetravalence left a reply on Eloquent Model's Created_at And Updated_at Do Not Work • 2 months ago

@Sergiu17 Eloquoent's documentation shows this "If you would like to generate a database migration when you generate the model, you may use the --migration or -m option:" then I don't understand what the two constants are supposed to do

Tetravalence started a new conversation Eloquent Model's Created_at And Updated_at Do Not Work • 2 months ago

Hello, according to Eloquent documentation if I need to customize the names of the columns used to store the timestamps, I may set the CREATED_AT and UPDATED_AT constants in my model, but this does not seem to work in my application.

'''

5th July, 2018

Tetravalence started a new conversation What Is The Difference Between Tag And Provider Option In Vendor:publish Command? • 3 months ago

Could someone please explain me the difference between tag and provider option in vendor:publish command issued with php artisan? Does this snippet of code

$this->publishes([
            dirname(dirname(__FILE__)).
                '/config/mypackage.php' => config_path('mypackage.php'),
        ], 'mypackage');

seems to work exactly like this and why?

$this->publishes([
            dirname(dirname(__FILE__)).
                '/config/mypackage.php' => config_path('mypackage.php'),
        ]);

1st July, 2018

Tetravalence left a reply on Modifying Column Type To BigIncrements Without DBAL Library • 3 months ago

@Thyrosis: quite right too but I might need to install the package on, let's say, about twenty sites. I prefer a procedure performed by the package itself . Unfortunately, as you say, any user data is lost and the customer could get angry.

Tetravalence started a new conversation Modifying Column Type To BigIncrements Without DBAL Library • 3 months ago

Hello, according to Laravel's documentation in order to modify existing column types, the Doctrine DBAL library has to be installed. Furthermore only certain column types can be "changed". I'm working on an blog package and I need the 'id' column to be bigIncrements instead of increments provided as default in the Laravel migration file for the 'users' table. My solution is to use the Schema facade to drop the 'id' column via 'up' method from migration class of the package, then restore the 'id' column with the new type:

 if (Schema::hasColumn('users', 'id')) {
    Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('id');
                //$table->bigIncrements('id');
        });
        Schema::table('users', function (Blueprint $table) {
                $table->bigIncrements('id')->first();
        });
}

Is this the right way to modify an existing migration without DBAL library? I don't understand because I have to create the 'id' column in a separate Schema block whereas if I try to use dropColumn and bigIncrements methods together then Laravel returns a message error.

15th June, 2018

Tetravalence left a reply on How To Grab Error Code When .env File Does Not Exist? • 4 months ago

@Snapey: OK, now if I run the command php artisan config:cache for deploying my application to production I still get the 500 error message from the server when .env file does not exist in the root of the application directory. So I guess I have overlooked some basic information about the deployment procedure. Thanks for all the replies

11th June, 2018

Tetravalence started a new conversation How To Grab Error Code When .env File Does Not Exist? • 4 months ago

Hello, I would like my package to handle the Laravel request when .env file does not exist in the application directory and the web server send the 500 error. Should I use both controller and view for this purpose or I have to register an Exception Handler?

5th April, 2018

Tetravalence left a reply on Defining Middleware • 6 months ago

OK, thank you for replying

Tetravalence started a new conversation Defining Middleware • 6 months ago

Hello! I'm new to Laravel, sorry for this silly question but I don't understand how/where $request object defines the age public property in "Defining Middleware" guide to Laravel 5.6

Edit Your Profile
Update

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