I have upload function and view.
Someone could tell me how I should edit my function in controller and view to add dropzone.
Here is my controller and view:
Controller:
public function getUpload()
{
return View::make('foto/upload');
}
public function postUpload()
{
$file = Input::file('image');
$filename = $file->getClientOriginalName();
$path = 'uploads';
return $file->move($path, $filename);
}
View:
{{Form::open(array('url' => 'foto/upload', 'files' => true))}}
{{Form::file('image')}}
{{Form::submit('Upload')}}
{{Form::close()}}
my
<head>
<link rel="stylesheet" href="http://adres/assets/css/bootstrap.min.css">
<link rel="stylesheet" href="http://adres/assets/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="http://adres/assets/css/dropzone.css">
<script type="text/javascript" src="http://adres/assets/js/jquery.js"></script>
<script type="text/javascript" src="http://adres/assets/js/dropzone.js"></script>
<style>
body { padding-top: 70px; }
</style>
</head>
This isn't really a Laravel specific question.
But this is how you add a class attribute in Form::open method. You just have to add it into the options array. like so: {{Form::open(array('url' => 'foto/upload', 'files' => true, 'class' => 'dropzone'))}}, as long as it's these "reserved" word: ['method', 'url', 'route', 'action', 'files'], Form::open will just throw your options array property=>value pair into the form element.
Related
I want to create an automatic chat system with Botman, but I have a problem. I do not receive a response when I send a message, and i get this message in console, "chat.js:1 POST http://127.0.0.1:8000/botman 404 (Not Found) (anonymous) # chat.js:1 t.exports # chat.js:1 t.exports # chat.js:1 Promise.then (async) r.request # chat.js:1 r. # chat.js:1 (anonymous) # chat.js:1 callAPI # chat.js:1 e.say # chat.js:1 r.handleKeyPress # chat.js:1 m # chat.js:1 chat.js:1 Uncaught (in promise) Error: Request failed with status code 404 at t.exports (chat.js:1:13996) at t.exports (chat.js:1:17470) at d. (chat.js:1:12823)" So here is my code
//route :
Route::get('/show_my_chat_form', 'BotManController#index')->name('chatform');
Route::get('/botman', 'BotManController#handle');
Route::post('/botman', 'BotManController#handle');
//here is my Controller
use BotMan\BotMan\BotMan;
use Illuminate\Http\Request;
use BotMan\BotMan\Messages\Incoming\Answer;
class BotManController extends Controller
{
public function index()
{
return view('chatform');
}
public function handle($language)
{
$botman=app("botman");
$botman->hears("{message}", function($botman,$message)
{
if ($message == "Hello")
{
$this->askName($botman);
}
else
{
$botman->reply("Please write hi to start conversation! ");
}
});
$botman->listen();
}
public function askName($language,$botman)
{
$botman->ask("what's your name? ", function(Answer $answer)
{
$name=$answer->getText();
$this->says("nice to met you M.-Mm ".$name);
});
//the config.php and web.php located in /config/botman/..
//config.php
<?php
return [
'conversation_cache_time' => 40,
'user_cache_time' => 30,
];
//web.php
<?php
return [
'matchingData' => [
'driver' => 'web',
],
];
//view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Form</title>
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget#0/build/assets/css/chat.min.css">
<style>
html,
body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
</style>
</head>
<body>
</body>
<script>
var botmanWidget = {
aboutText: 'write',
introMessage: "✋hi",
//frameEndpoint: ''
};
</script>
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget#0/build/js/widget.js'></script>
</html>
I'm trying to follow this tutorial https://laravelcode.com/post/laravel-full-calendar-tutorial-example-using-maddhatter-laravel-fullcalendar. I completed every steps but the calendar still does not appear, only the Laravel header and the "Full Calendar Example" writing but not the calendar itself or if I remove "extends('layout.php')" nothing appears. :( What could be the problem? I hope someone can give a quick answer. Sorry if it's a bad question here.
My code:
config/app.php
'providers' => [
.....
.....
MaddHatter\LaravelFullcalendar\ServiceProvider::class,
],
'aliases' => [
.....
.....
'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class,
]
database/migrations/CreateEventsTable
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('events', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->date('start_date');
$table->date('end_date');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop("events");
}
}
app/Event.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
protected $fillable = ['title','start_date','end_date'];
}
database/seeds/AddDummyEvents.php
use Illuminate\Database\Seeder;
use App\Event;
class AddDummyEvent extends Seeder
{
public function run()
{
$data = [
['title'=>'Demo Event-1', 'start_date'=>'2017-09-11', 'end_date'=>'2017-09-12'],
['title'=>'Demo Event-2', 'start_date'=>'2017-09-11', 'end_date'=>'2017-09-13'],
['title'=>'Demo Event-3', 'start_date'=>'2017-09-14', 'end_date'=>'2017-09-14'],
['title'=>'Demo Event-3', 'start_date'=>'2017-09-17', 'end_date'=>'2017-09-17'],
];
foreach ($data as $key => $value) {
Event::create($value);
}
}
}
routes/web.php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('events', 'EventController#index');
app/Http/Controllers/EventController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Calendar;
use App\Event;
class EventController extends Controller
{
public function index()
{
$events = [];
$data = Event::all();
if($data->count()) {
foreach ($data as $key => $value) {
$events[] = Calendar::event(
$value->title,
true,
new \DateTime($value->start_date),
new \DateTime($value->end_date.' +1 day'),
null,
// Add color and link on event
[
'color' => '#f05050',
'url' => 'pass here url and any route',
]
);
}
}
$calendar = Calendar::addEvents($events);
return view('fullcalendar', compact('calendar'));
}
}
resources/views/fullcalendar.blade.php
#extends('layouts.app')
#section('style')
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
#endsection
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Full Calendar Example</div>
<div class="panel-body">
{!! $calendar->calendar() !!}
</div>
</div>
</div>
</div>
</div>
#endsection
#section('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar->script() !!}
#endsection
Unsure why it was left out of the tutorial, but they didn't have you set up a layout blade file. They also forgot to include jquery. If you change fullcalendar.blade.php to the following code it works.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<link rel="stylesheet" type="text/css"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet"
ref="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
<body>
<div class="container" style="margin-top: 100px">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Full Calendar Example</div>
<div class="panel-body">
{!! $calendar->calendar() !!}
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
{!! $calendar->script() !!}
</html>
Look in the EventController in the calender() function
The return view() is trying to return "calender", change it to calendar to match the view name you created in views.
I have a small problem with redirecting a user once page is created.
Problem is that all together I have 3 returns within 2 functions and obviously that can't be done and I am looking for a way to change this but I don't know what should it be.
Process is like this.
User creates a page: code is saved into javascript variable.
User chooses a name for a page: code is saved into another javascript variable.
Ajax is passing these values to Controller and then:
public function postDB(Request $request) {
$newName = $request->input('name_website');
$newLat = $request->input('newCode');
$websites = new Website();
$websites->name = $newName;
$websites->html = $newLat;
$websites->save();
return $newName;
return $this->website($newName);
}
public function website($newName)
{
dd($newName);
Website::where('name', $newName)->first()->html;
return view('layouts/website');
}
After saving into a database I am returning value of $newName which is the actual name for a website or I should say URL and also return (call another function) which then search for html code that matches a name, and return view that deals with displaying it:
#extends('layouts.master') #section('title', 'Website Builder') #section('content')
<meta name="csrf-token" content="{{ csrf_token() }}" />
{{html_entity_decode($name->html)}}
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
axios.get('/name').then(
html => document.querySelector('html').innerHTML = html
);
</script>
</html>
#endsection #show
So basically after user saved it to database I want to redirect them to a page which is in saved variable $newName and retrieve + display html that matches name that is in the variable.
Route::group(['middleware' => ['web']], function () {
Route::get('home', 'BuilderController#homepage');
Route::get('template', 'BuilderController#templates');
Route::post('template', 'BuilderController#postDB');
Route::get('logout', 'BuilderController#getLogout');
Route::get('/{name}', 'BuilderController#website');
});
template.blade.php
<button onClick=" updateDatabase(this);" type="button" class="form-control margin btn btn-success" id="getRequest changes">
Save Website
</button>
JS:
var web_name;
function updateDatabase(newCode, name_website)
{
code2 = document.getElementById("content-link2").innerHTML;
web_name = ($('#website_name').val());
// make an ajax request to a PHP file
// on our site that will update the database
// pass in our lat/lng as parameters
$.post('http://localhost/template', {
_token: $('meta[name=csrf-token]').attr('content'),
newCode: (code2),
name_website: (web_name),
})
.done(function() {
})
.fail(function() {
alert("error");
});
}
EDIT: I have update my code like I was told in the answer below but now I am getting:
Trying to get property of non-object (View: C:\xampp\htdocs\fyproject\resources\views\layouts\website.blade.php)
in 87bb9cbe60b5bd1fe6f78e1246f2227dbd0f328f.php line 5
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\xampp\htdocs\fyproject\storage\framework\views/87bb9cbe60b5bd1fe6f78e1246f2227dbd0f328f.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'name' => ' <title>Template 1</title> <link href="http://localhost/templates/css.css" rel="stylesheet" type="text/css"> <div class="logo"> <img class="images" id="image" src="#" alt="Your Logo"> </div> <div contenteditable="true" id="content" class="draggable ui-widget-content refresh ui-draggable ui-draggable-handle" style="position: relative; left: 209px; top: 139px;"><p>Change Text inside this box</p></div> <div id="editTxt" class="refresh" contenteditable="true"> <p>This text can be by the user.</p> </div> ')) in CompilerEngine.php line 59
at CompilerEngine->get('C:\xampp\htdocs\fyproject\resources\views/layouts/website.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'name' => ' <title>Template 1</title> <link href="http://localhost/templates/css.css" rel="stylesheet" type="text/css"> <div class="logo"> <img class="images" id="image" src="#" alt="Your Logo"> </div> <div contenteditable="true" id="content" class="draggable ui-widget-content refresh ui-draggable ui-draggable-handle" style="position: relative; left: 209px; top: 139px;"><p>Change Text inside this box</p></div> <div id="editTxt" class="refresh" contenteditable="true"> <p>This text can be by the user.</p> </div> ')) in View.php line 149
I would suggest something like this:
public function postDB(Request $request) {
$newName = $request->input('name_website');
$newLat = $request->input('newCode');
$websites = new Website();
$websites->name = $newName;
$websites->html = $newLat;
$websites->save();
// Now we go to our other function
$this->website($newName);
}
public function website($newName)
{
// Return our "website" object
$website = Website::where('name', $newName)->first();
// Pass the contents of the "html" property to the view
return view('layouts/website', [
'html' => $website->html
);
}
This will give you access to the content of your "html" attribute in your blade template as $html.
Edit
If you are using your controller for an API you might consider not returning a view but instead a json response which you can listen for:
return response()->json([
'url' => $website->name,
'html' => $website->html
]);
You can then handle the content of the page or redirect using javascript
In my controller I have added this code.For different view files there are different functions.How can I add meta tags for different function for different views?
This is my controller:
<?php
class home extends CI_Controller {
function index()
{
$data['meta_title'] = 'Tracenow | iOS Version';
$data['meta_description'] = 'Responsive HTML5 Theme in iOS Style';
$data['meta_keywords'] = 'responsive html5 theme, ios, android, material design, landing, application, mobile, blog, portfolio, bootstrap 3, css, jquery, flat, modern';
$data['meta_author'] = '8Guild';
$data['meta_viewport'] = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
$this->load->view('home_page/home_page');
}
function about()
{
$this->load->view('home_page/about');
}
function blog()
{
$this->load->view('home_page/blog');
}
function blog_single()
{
$this->load->view('home_page/blog-single');
}
}
?>
For this you can simply use this in your controller:
$data['meta_title'] = 'Your meta title';
$data['meta_description'] = 'Your meta description';
$data['meta_keywords'] = 'Your meta keywords';
And you view should be like:
<title><?php echo $meta_title; ?></title>
<meta name="description" content="<?php echo $meta_description; ?>" />
<meta name="keywords" content="<?php echo $meta_keywords; ?>" />
Hopefully it will help you. or if you need any help please comment below.
You can use this library
Meta Tags
On your Controller
$data['metas'] = array(
array('name'=>'description', 'content'=>'A short but sweet DEFAULT description of this fine site'),
array('name' =>'keywords', 'content'=>'some awesome DEFAULT keywords for those rascally web crawlers')
);
On your View
<?php
foreach($metas as $meta)
{?>
<meta name="<?=$meta['name']?>" content="<?=$meta['content']?>" />
<?php }?>
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->helper('html'); //Load global helper 'html'
}
[...]
//in controller: meta tag
$meta = array(
array(
'name' => 'robots',
'content' => 'no-cache'
),
array(
'name' => 'description',
'content' => 'My Great Site'
),
array(
'name' => 'keywords',
'content' => 'love, passion, intrigue, deception'
),
array(
'name' => 'robots',
'content' => 'no-cache'
),
array(
'name' => 'Content-type',
'content' => 'text/html; charset=utf-8', 'type' => 'equiv'
)
);
//HTML
<!DOCTYPE html>
<head>
<title></title>
<?= meta($meta) ?> //use helper HTML to show meta tag
</head>
// Generates:
// <meta name="robots" content="no-cache" />
// <meta name="description" content="My Great Site" />
// <meta name="keywords" content="love, passion, intrigue, deception" />
// <meta name="robots" content="no-cache" />
// <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
Font:https://codeigniter.com/userguide3/helpers/html_helper.html?highlight=helper
In your controller :
$this->output->set_common_meta($page_title, $page_description, $page_keywords); // for title, description, keywords
$this->output->set_meta('property_name', 'property_value'); // for other properties
I'm trying to find a trick to save a picture coded in Data-URI like this:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1MAAAE7CAYAAAA4gNuCAAAgAElEQ…
i/fPjJwSa8k8blB7TPIbffod14w9E/Baq03hUCXPf2/wK6K8SbNo44VwAAAABJRU5ErkJggg==
Another question: Where the picture is saved in the first time in the server? Browser?
JS: save image to user's disk using javascript,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript">
window.onload = function () {
var img = document.getElementById('embedImage');
var button = document.getElementById('saveImage');
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA'+
'AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO'+
'9TXL0Y4OHwAAAABJRU5ErkJggg==';
img.onload = function () {
button.removeAttribute('disabled');
};
button.onclick = function () {
window.location.href = img.src.replace('image/png', 'image/octet-stream');
};
};
</script>
</head>
<body>
<img id="embedImage" alt="Red dot"/>
<input id="saveImage" type="button" value="save image" disabled="disabled"/>
</body>
</html>
PHP: http://j-query.blogspot.com/2011/02/save-base64-encoded-canvas-image-to-png.html
<?php
// requires php5
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
?>
EDIT JS solution 2 (fiddle: http://jsfiddle.net/KAdN8/):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript">
var img = document.getElementById('embedImage');
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( 'click', true, false );
img.dispatchEvent(evObj);
} else if( document.createEventObject ) {
img.fireEvent('on'+evt);
}
</script>
</head>
<body>
Download
</body>
</html>