mardi 5 octobre 2021

Route isn't redirecting me to the correct page. It just shows me the same page but the url changes

I've made a blog template but I having trouble making the routes. When I click on the link, it should redirect me to the article page. Instead it just redirects me to the same page/same exact location. Here's my code:

<section id="about" class="ts-block" >
    <div id="cards_landscape_wrap-2">
    <div class="container">
        <div class="row">
        @foreach($blogs as $blog)
            <div class="col-lg-4">
                <a href=>
                    <div class="card-flyer"  >
                        <div class="text-box">
                            <div class="image-box ">
                                <img src="/images/blogs/" alt="" class="img-fluid rounded mx-auto d-block" width="100%"/>
                            </div>
                            <div class="text-container">
                                <h6></h6>
                                <p style="max-width: 18rem;"class="ts-opacity__50"></p>
                            </div>
                            <div class="card-footer">
                                        <span class="text-primary font-weight-bold">Read</span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            @endforeach
        </div>
    </div>
    </div>
    </section>    

BlogController :

public function getArticles()
{
    return view('blog')->with([
        'blogs' => Blog::all(),
    ]);
}

Routes :

Route::get('/blog/', [App\Http\Controllers\BlogController::class, 'index'])->name('blog');
Route::get('blogs/','App\Http\Controllers\BlogController@getArticles')->name('blogs.show');
Route::get('/admin/blog', 'App\Http\Controllers\BlogController@getBlog')->name('admin.blog');
Route::resource('/blog','App\Http\Controllers\BlogController');

The routes that supposed to be redirecting me to another page is the 2nd one with BlogController@getArticles. The other routes are fine a have no problem.

Can someone kindly show me what I did wrong ?



via Chebli Mohamed

lundi 4 octobre 2021

Using DialogFlow ES EventInput on Laravel + SQLite

I'm new to DialogFlow API and created Laravel sandbox app, that takes some query data and sends it to a database. I would like to use HTTP Protocol to start a conversation via EventQuery, but could not figure out the whole way to do it.

There is a JavaScript app that uses hardcoded event query parameters and sends it to a simple UI. This is almost it, but without db.

EventQuery class: https://github.com/googleapis/google-cloud-php-dialogflow/blob/master/src/V2/EventInput.php

Laravel sandbox app: https://phpsandbox.io/e/x/gziyh?layout=EditorPreview&defaultPath=%2F&theme=dark&showExplorer=no&openedFiles=

JavaScript app with eventQuery: https://github.com/fitwist/chatbot-app

How do I send an EventQuery request, made of form data, send data to SQLite at the same time and continue the dialogue in simple UI?

Possible template:

<?php 
namespace Google\Cloud\Dialogflow\V2;

use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;

class EventInput extends \Google\Protobuf\Internal\Message
{

    private $name = '';
    private $parameters = null;
    private $language_code = '';

    public function __construct($data = NULL) {
        \GPBMetadata\Google\Cloud\Dialogflow\V2\Session::initOnce();
        parent::__construct($data);
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($var)
    {
        GPBUtil::checkString($var, True);
        $this->name = $var;

        return $this;
    }

    public function getParameters()
    {
        return isset($this->parameters) ? $this->parameters : null;
    }

    public function hasParameters()
    {
        return isset($this->parameters);
    }

    public function clearParameters()
    {
        unset($this->parameters);
    }

    public function setParameters($var)
    {
        GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class);
        $this->parameters = $var;

        return $this;
    }

    public function getLanguageCode()
    {
        return $this->language_code;
    }

    public function setLanguageCode($var)
    {
        GPBUtil::checkString($var, True);
        $this->language_code = $var;

        return $this;
    }

}
?>

<!DOCTYPE html>
<html>
    

    <section class="container grey-text">
        <h4 class="center">Add a Pizza</h4>
        <form class="white" action="add.php" method="POST">
            <label>Your Email</label>
            <input type="text" name="email">
            <label>Your Name</label>
            <input type="text" name="name">
            <label>Company</label>
            <input type="text" name="company">
            <div class="center">
                <input type="submit" name="submit" value="Submit" class="btn brand z-depth-0">
            </div>
        </form>
    </section>
</html>

I would appreciate any of your help, because the struggle has already taken three months.



via Chebli Mohamed

Compare Arabic words in Laravel

I'm creating a Quiz type application it has several questions like :

  1. During my free time I most enjoy: (translated to Arabic) أكثر ما أستمتع به في أوقات فراغي:

Now i have answers saved in my database

listening to music and talking to my friends (translated to Arabic) الاستماع إلى الموسيقى والتحدث مع أصدقائي

when user types in some text in Arabic i have to compare both the text whether the answer is correct or not.

$srting1= الاستماع إلى الموسيقى والتحدث مع أصدقائي
$dbstring= الاستماع إلى الموسيقى والتحدث مع أصدقائي

if($srting1==$dbstring)
{
  echo "string matched";
}

Any suggestion please.

Thanks



via Chebli Mohamed

Symfony\Component\Routing\Exception\RouteNotFoundException; Route [home.getstarted] not defined

I am new to web development and I am doing this as my project. Your help in solving this will go a long way.

I am getting this route error on 4 of my blade PHP code. The first error comes in line:429. How do I correct it?

  ** * Get the URL to a named route.

 *

 * @param  string  $name

 * @param  mixed  $parameters

 * @param  bool  $absolute

 * @return string

 *

 * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException

 */

public function route($name, $parameters = [], $absolute = true)

{

    if (! is_null($route = $this->routes->getByName($name))) {

        return $this->toRoute($route, $parameters, $absolute);

    }



    throw new RouteNotFoundException("Route [{$name}] not defined.");

}



/**

 * Get the URL for a given route instance.

 *

 * @param  \Illuminate\Routing\Route  $route

 * @param  mixed  $parameters

 * @param  bool  $absolute

 * @return string

 *

 * @throws \Illuminate\Routing\Exceptions\UrlGenerationException

 */

public function toRoute($route, $parameters, $absolute)

{

    $parameters = collect(Arr::wrap($parameters))->map(function ($value, $key) use ($route) {**

here is the second PHP code with the error here: <form action="" method="post" class="getStartedForm">

</nav>

                    </div>

                    <div class="input-section recepiet">

                        <div class="money-input-field">

                            <input type="number" id="final_amount" placeholder="83,876">

                            <span></span>

                        </div>

                        <div class="money-currency">

                            <a href="#" data-bs-toggle="dropdown" aria-expanded="false"><span><img id="country_flag" src="" alt=""> <span id="currency_name"> </span>&nbsp <span class="iconify" data-icon="dashicons:arrow-down-alt2" data-inline="fa

                            <ul class="dropdown-menu dropdown-menu-end currency" id="currencyList">

                            </ul>

                            <input type="hidden" name="currency_name" id="currency_symbol">

                        </div>

                    </div>

                    <div class="calculation-checkout-btn">

                        <form action="" method="post" class="getStartedForm">

                            @csrf

                            <input type="hidden" value="" name="charge">

                            <input type="hidden" value="" name="currency">

                            <input type="hidden" value="" name="amount">

                            <input type="hidden" value="" name="withdrawmethod">

                            <button type="submit" id="getStarted"></button>

                        </form>


                    </div>

                </div>

            </div>

        </div>

    </div>

</div>

The third PHP code, the error came in line 25

<?php

namespace App\Http\Middleware;

use Closure;

class Localization

{

    /**

     * Handle an incoming request.

     *

     * @param  \Illuminate\Http\Request  $request

     * @param  \Closure  $next

     * @return mixed

     */

    public function handle($request, Closure $next)

    {

        if (\Session::has('locale')==true) {

            \App::setlocale(\Session::get('locale'));

        }

        else{

            \Session::put('locale',env('DEFAULT_LANG','en'));

            \App::setlocale(\Session::get('locale'));

        }

        return $next($request);

    }

}

the Forth PHP code with error in $request = Illuminate\Http\Request::capture(). Below is the code:

    | We need to illuminate PHP development, so let us turn on the lights.

| This bootstraps the framework and gets it ready for use, then it

| will load up this application so that we can run it and send

| the responses back to the browser and delight our users.

|

*/

 

$app = require_once __DIR__.'/script/bootstrap/app.php';

 

/*

|--------------------------------------------------------------------------

| Run The Application

|--------------------------------------------------------------------------

|

| Once we have the application, we can handle the incoming request

| through the kernel, and send the associated response back to

| the client's browser allowing them to enjoy the creative

| and wonderful application we have prepared for them.

|

*/

 

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

 

$response = $kernel->handle(

    $request = Illuminate\Http\Request::capture()

);

 

$response->send();

 

$kernel->terminate($request, $response);

What can be done to remedy this error?



via Chebli Mohamed

dimanche 3 octobre 2021

relationship laravel belongsToMany user roles

i´m traying to create relationship belongsToMany with user role and pivot table assigned_roles.

i have this relation in AssignedRole model

/**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
     public function user()
     {
        return $this->belongsToMany('App\User');
     }

     /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function roleName()
    {
        return $this->belongsTo('App\Role', 'id', 'role_id');
    }

and in my model User:

/**
 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
 */
public function roles()
{
    return $this->belongsToMany('App\AssignedRole', 'entity_id');
}

and

/**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function role()
    {
        return $this->belongsTo('App\AssignedRole', 'entity_id');
    }

but when i´m traying to call roles in my controller to show all roles from users, return this:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'gruposuite.entity_id' doesn't exist (SQL: select `assigned_roles`.*, `entity_id`.`user_id` as `pivot_user_id`, `entity_id`.`assigned_role_id` as `pivot_assigned_role_id` from `assigned_roles` inner join `entity_id` on `assigned_roles`.`id` = `entity_id`.`assigned_role_id` where `entity_id`.`user_id` in (1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 76))

i don´t know that i´m doing wrong...

i hope that anybody can help me. thanks

Update

i can to do my relationship with:

model User

/**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function role()
    {
        return $this->hasMany('App\AssignedRole', 'entity_id');
    }

model AssignedRole

/**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
     public function user()
     {
        return $this->belongsTo('App\User');
     }

this it´s my result:

{"id":98,"role_id":3,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null},{"id":106,"role_id":9,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null},{"id":111,"role_id":7,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null},{"id":112,"role_id":5,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null},{"id":113,"role_id":6,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null},{"id":115,"role_id":4,"entity_id":1,"entity_type":"App\\User","restricted_to_id":null,"restricted_to_type":null,"scope":null}]}

But now i need role´s name how i can to do this?

Thanks



via Chebli Mohamed

Having trouble creating an alternating horizontal about us page

I made an about us in html and now I want to convert in to a dynamic page using laravel. The thing is I don't know how to make the image/text alternate. I've already made one section of the about us page and I'm displaying it on the [landing page][1]. Now when the user clicks on the learn more button, I want it to take him to this page 'https://ift.tt/3l3fGTL', which you can see has the alternating horizontal look which I've made it with html. I want it to be dynamic. Here's the code that I've written for the first section.

<section id="about-us">
        @foreach($abouts as $about)
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="ts-block pr-3">
                            <div class="ts-title">
                                <h2></h2>
                            </div>
                            <!--end ts-title-->
                            <p></p><p></p>
                            <a href="/about" class="btn btn-primary mr-3 my-2">
                                <i class="fa fa-arrow-right small ml-3 ts-opacity__50"></i>
                            </a>
                        </div>
                    </div>
                    <!--end col-md-6-->
                </div>
                <!--end row-->
            </div>
            <!--end container-->

            <div class="ts-background d-none d-sm-block" data-bg-color="#fafafa" data-bg-parallax1="scroll" data-bg-parallax-speed="3">
                <div class="owl-carousel w-50 ts-push-left__100 h-100 ts-parallax-element1" data-owl-loop="1" data-owl-nav-container="#carousel-external-control">
                    <div class="ts-background-image" data-bg-image="" alt="img"></div>
                </div>
                <!--end owl-carousel-->
            </div>
            <!--end ts-background-->
        </section>
    @endforeach

If anyone who has learnt and is very good at using laravel, can you kindly assist complete this page? [1]: https://i.stack.imgur.com/CCDgA.png



via Chebli Mohamed

relationship laravel empty result

I´m traying create relation ship in my model user-roles.

Firt i have to say that i´m using Bouncer library to use permission and roles.

I have my model User with this realation:

public function roles()
{
   return $this->belongsTo('App\AssignedRoles', 'entity_id');
}

and my model AssignedRole:

public function user()
{
  return $this->hasMany('App\User', 'id', 'entity_id');
}

and

public function roleName()
{
  return $this->belongsTo('App\Role', 'id', 'role_id');
}

in my controller i´m trayin return all role that it has one User, using this:

$employee = User::with('roles')->get();

but return this:

Array([roles] => )

what i´m doing wrong?

I need create user list with his roles.

Thanks for read and sorry for my english



via Chebli Mohamed