Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it? How to Show the Poll Pages? #117

Open
raisrindo opened this issue Apr 5, 2022 · 1 comment
Open

How to use it? How to Show the Poll Pages? #117

raisrindo opened this issue Apr 5, 2022 · 1 comment

Comments

@raisrindo
Copy link

raisrindo commented Apr 5, 2022

Hi, I'm a Newbie. I don't understand how to use the package. I've already install the package and success until the migration. But, how to display the page? do I need to create the views, controller, and configure the routes first? Thanks

@raisrindo raisrindo changed the title How to use it? How to use it? How to Show the Poll Pages? Apr 5, 2022
@jyrjsinhatfolium
Copy link

@raisrindo try this way..........

Try Following Steps After Installing the package and migrations Completely ! Otherwise You Will Get an error !

Create Controller:

php artisan make:controller PollController

Paste Below Code in Your PollController.php which is located atapp/http/controllers/ :

<?php

namespace App\Http\Controllers;
use Inani\Larapoll\Poll;


use Illuminate\Http\Request;

class PollController extends Controller
{
    public function index(Request $request){

          $polls = Poll::all();
         
          return view('polls.index',compact('polls'));
       
    }
}

?>

Create index.blade.php file in resources/views/polls/ and paste the code below init :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Polls</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
      <div class="row">
          @foreach($polls as $poll)
             <div class="col-md-12">
                    {{ PollWriter::draw(Inani\Larapoll\Poll::find($poll->id)) }}
             </div>
           @endforeach
       </div>
</body>
</html>

Now in routes/web.php paste the code below :

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PollController;


Route::get('/', function (Request $request) {
    return view('welcome');
});


Route::get('/polls',[PollController::class,'index']);

?>

Now hit the url in browser :

http://127.0.0.1:8000/polls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants