dimanche 2 juin 2019

send an email after veryfy the email in Laravel 5.7

I am working with laravel 5.7 and has designed a verify system in controller like this,

 public function verifyUser($token)
    {
        $verifyUser = VerifyUser::where('token', $token)->first();
        if(isset($verifyUser) ){
            $user = $verifyUser->user;
            if(!$user->verified) {
                $verifyUser->user->verified = 1;

                $verifyUser->user->save();

                $info = "Your e-mail is verified. You can now login.";
            }else{
                $info = "Your e-mail is already verified. You can now login.";
            }
        }else{
             return redirect()->back()->with('warning', "Sorry your email cannot be identified.");
        }

         return redirect()->back()->with('info', $info);
    }
}

now i need send a default email to admin admin@mybook.net to notify after veryfied above system inside this methods. how can I manage this?



via Chebli Mohamed

Keep getting count(): Parameter must be an array or an object that implements Countable

I have problem while storing data into database. It is saying count(): Parameter must be an array or an object that implements Countable

Here is my code.

$InsertRecords  = new App\Two263;
$InsertRecords->user_id = 1;
$InsertRecords->aca_year = "test";
$InsertRecords->school_id = '1';
$InsertRecords->school_name = '1';
$InsertRecords->prog_code = "1";
$InsertRecords->prog_name = "2";
$InsertRecords->no_stud_appeared = "3";
$InsertRecords->no_stud_passed = "14";
$InsertRecords->save();

Here is my database structure screenshot: http://prntscr.com/nwj0qj

Error screenshot: http://prntscr.com/nwj167

If I attempt to save record, this error comes up. I don't know what it has to do with the count function.

It's been 6 hours I'm trying to figure out this issue. Please help.

Thanks!



via Chebli Mohamed

Why Laravel joined query modifies order if distinct is used?

I have the following query:

$recentTasks = Task::where('assigned_to','=',$user->id)->join('task_comments','task_comments.task_id','=','tasks.id')->orderBy('task_comments.updated_at','DESC')->select('tasks.*')->limit(10)->get();

What I need is a list of tasks that had recent comments. So I joined the comments table and ordered by it. It works and recently commented tasks are at the top. But it has duplicates, so one task can appear multiple times. If I insert a ->distinct() or ->distinct('tasks.id') then the duplicates are gone, but the sort by order is wrong.

How can I keep the sorting order but remove duplicates?



via Chebli Mohamed

samedi 1 juin 2019

How to print directly to the printer using only Laravel or make a pdf and print it directly from the browser?

I need to print all the grades by level from a school, I'm working using Laravel and I have searched for the way to do it but I could'nt find the answer. Do someone here knows how to send a view to be printed directly to the printer? or instead, how to make a pdf with all the grades and then use the pdf software to print? I prefer to not using third party plugins also, could someone give me ligth about this issue?



via Chebli Mohamed

Using custom schema builder with laravel-cassandra

I'm using this library shso/laravel-cassandra to access my cassandra instance from Lumen and everything is working fine. but when I try to use Laravel migrate I get this exception

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


Exception trace:
 () at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Connection.php:326
 Illuminate\Database\Connection->Illuminate\Database\{closure}() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Connection.php:657
 Illuminate\Database\Connection->runQueryCallback() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Connection.php:624
 Illuminate\Database\Connection->run() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Connection.php:333
 Illuminate\Database\Connection->select() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Connection.php:304
 Illuminate\Database\Connection->selectFromWriteConnection() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Schema/Builder.php:75
 Illuminate\Database\Schema\Builder->hasTable() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php:169
 Illuminate\Database\Migrations\DatabaseMigrationRepository->repositoryExists() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Migrations/Migrator.php:583
 Illuminate\Database\Migrations\Migrator->repositoryExists() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:91
 Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /home/masoud/Codes/TheSite/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:63
 Illuminate\Database\Console\Migrations\MigrateCommand->handle() at n/a:n/a
 call_user_func_array() at /home/masoud/Codes/TheSite/api/vendor/illuminate/container/BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/masoud/Codes/TheSite/api/vendor/illuminate/container/BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/masoud/Codes/TheSite/api/vendor/illuminate/container/BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at /home/masoud/Codes/TheSite/api/vendor/illuminate/container/Container.php:576
 Illuminate\Container\Container->call() at /home/masoud/Codes/TheSite/api/vendor/illuminate/console/Command.php:183
 Illuminate\Console\Command->execute() at /home/masoud/Codes/TheSite/api/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /home/masoud/Codes/TheSite/api/vendor/illuminate/console/Command.php:170
 Illuminate\Console\Command->run() at /home/masoud/Codes/TheSite/api/vendor/symfony/console/Application.php:921
 Symfony\Component\Console\Application->doRunCommand() at /home/masoud/Codes/TheSite/api/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /home/masoud/Codes/TheSite/api/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /home/masoud/Codes/TheSite/api/vendor/illuminate/console/Application.php:90
 Illuminate\Console\Application->run() at /home/masoud/Codes/TheSite/api/vendor/laravel/lumen-framework/src/Console/Kernel.php:115
 Laravel\Lumen\Console\Kernel->handle() at /home/masoud/Codes/TheSite/api/artisan:35

This is the PHP code I wrote:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use ShSo\Lacassa\Schema\Grammar;

class CreateUsersByEmail extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        DB::connection()->setSchemaGrammar(new ShSo\Lacassa\Schema\Grammar());
        $schema = DB::connection()->getSchemaBuilder();
        $schema->blueprintResolver(function($table, $callback) {
            return new \ShSo\Lacassa\Schema\Blueprint($table, $callback);
        });

        $schema->create('users_by_email', function ($table) {
            $table->uuid('id');     //User ID
            $table->varchar("email");
            $table->varchar("first_name");
            $table->varchar("last_name");
            $table->timestamp("email_verified_at");
            $table->varchar("password");
            $table->varchar("token");
            $table->timestamp("created_at");
            $table->timestamp("updated_at");
            $table->primary("email");
        });
    }

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

I couldn't find any thing on google and I haven't been able to figure out what I'm doing wrong. any help is appreciated.



via Chebli Mohamed

Listen to incoming request for specific time inside laravel controller

I'm working on a game.

This is the scenario:

  1. First player request a challenge
  2. system will wait 5 seconds for another request
  3. IF another request does not come, system start a challenge with a bot

All three steps have to run in backend and As much as I know, there's some functions like sleep or usleep in php that will wait some specific seconds and then continue the code.

In my case I do not want my controller to sleep.

Note:

As you may know, I'm using laravel.

Does any one experience about this case?

public function start()
{
    $game = new \App\Models\Game();
    $lastGame = $game->orderBy('id', 'desc')->first();

    if( $lastGame->user_one != false && $lastGame->user_two == null )
    {
        return 'can join';
    }
    else if( $lastGame->user_one != null && $lastGame->user_two != null )
    {
        return 'newGameShould Create...';
    }

}



via Chebli Mohamed

The GET method is not supported for this route. Supported methods: PUT

I want to store the values to the Database and redirect to a new page but find this error. I changed my code many times but same error is displayed. I am continuously finding this error.Please if there is any tricks to avoid the error please provide it to me.I have tried many possible things but the error is same.

Route.php

            Route::get('/create',   ['as'=>'creates','uses'=>'CAsController@create2']);
            Route::put('/postca', 'CAsController@storing');



    <?php

    namespace App\Http\Controllers;
    use App\CAModel;
    use Illuminate\Http\Request;

   class CAsController extends Controller
    {
    public function create2(){
    return view('chartered.create');
}
public function storing(Request $request)
{
    // Handle File Upload
    if($request->hasFile('profile')){
        // Get filename with the extension
        $filenameWithExt = $request->file('profile')->getClientOriginalName();
        // Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
        // Get just ext
        $extension = $request->file('profile')->getClientOriginalExtension();
        // Filename to store
        $fileNameToStore= $filename.'_'.time().'.'.$extension;
        // Upload Image
        $path = $request->file('profile')->storeAs('public/profile', $fileNameToStore);
    } else {
        $fileNameToStore = 'noimage.jpg';
    }


    // Handle File Upload
    if($request->hasFile('certificate')){
        // Get filename with the extension
        $filenameWithExt1 = $request->file('certificate')->getClientOriginalName();
        // Get just filename
        $filename1 = pathinfo($filenameWithExt1, PATHINFO_FILENAME);
        // Get just ext
        $extension1 = $request->file('certificate')->getClientOriginalExtension();
        // Filename to store
        $fileNameToStore1= $filename1.'_'.time().'.'.$extension1;
        // Upload Image
        $path1 = $request->file('certificate')->storeAs('public/certificate', $fileNameToStore1);
    } else {
        $fileNameToStore1 = 'noimage.jpg';
    }

    $ca = new CAModel;
    $ca->fname = $request->input('fname');
    $ca->lastname = $request->input('lastname');
    $ca->username = $request->input('username');
    $ca->city = $request->input('city');
    $ca->state = $request->input('state');
    $ca->zip = $request->input('zip');
    $ca->phone = $request->input('phone');
    $ca->email = $request->input('email');
    $ca->gstno = $request->input('gstno');
    $ca->website = $request->input('website');
    $ca->services = $request->input('services');
    $ca->profile = $fileNameToStore;
    $ca->certificate = $fileNameToStore1;  
    $ca->save();
    return redirect('/postca');
}

}

         <p>Register for TaxRx.</p>
        <form method="POST" action="">
          @csrf
          @method('put')
                <div class="form-group">
                <input type="text" class="form-control" placeholder="Name" style="text-transform: uppercase;" value="" readonly>
                </div>



via Chebli Mohamed